[quote]
1. ระบุสูตรนี้ในฟิลด์ DocNo ที่เป็น runno ของเอกสารครับ
LastNo := @Subset(@DbLookup("":"Nocache" ; ThisServer : ThisDB ;
"lookupReceiveNo" ; DocNo ; 2) ; 1);
Runno := @If(@IsError(LastNo); ""; @Right(@Text(LastNo); "-"));
NewCurrentYear := @Text(@Year(@Today));
CurrentYear := @If(@Left(@Text(LastNo); "-") = ""; NewCurrentYear;
@Left(@Text(LastNo); "-"));
OldRunning := @If(RunNo = ""; 0; @TextToNumber(RunNo));
NewRunning := OldRunning + 1;
NewPartNo := @Repeat("0" ; 5 - @Length(@Text(NewRunning))) + @Text(NewRunning);
NewCurrentYear + "-" + @If(CurrentYear = NewCurrentYear; NewPartNo;"00001")
[/quote]
ตรงนี้ สร้าง field ชื่อ docno เมื่อเป็นตัวแสดงเลข RunNo ใช่ไหมครับ
[quote]
2. ใน event querysave ให้ระบุตามนี้ครับ
Dim w,x,y,z As Variant
Dim NewRunning As Long
Dim db As NotesDatabase
Dim w As New NotesUIWorkspace
Dim s As New NotesSession
Dim doc As Notesdocument
Dim note As NotesDocument
Dim uidoc As NotesUIDocument
Set db = s.CurrentDatabase
Set uidoc = w.CurrentDocument
Set note = uidoc.Document
If Uidoc.IsNewdoc Then
x=Evaluate(|@DbLookup("":"Nocache"; ThisServer:ThisDB; "lookupReceiveNo"; DocNo; 2)|, Curdoc)
If Isarray(x) Then
If x(0) = "" Or Instr(1, x(0), "-") = 0 Then
Runno = "0"
Else
Runno = Right(x(0), Instr(1, x(0), "-")-1)
End If
NewCurrentYear = Cstr(Year(Today))
If Instr(1, x(0), "-") = 0 Then
CurrentYear = NewCurrentYear
Else
CurrentYear = Left(Cstr(x(0)), Instr(1, x(0), "-")-1)
End If
NewRunning = Clng(RunNo) + 1
NewLastNo = UDFRepeat("0", NewRunning, 5)
If Clng(NewLastNo) >Clng(Right(note.DocNo(0), Instr(1, Curdoc.DocNo(0), "-")-1)) Then
If CurrentYear = NewCurrentYear Then
LastNo = NewCurrentYear + "-" + NewPartNo
Else
LastNo = NewCurrentYear + "-" + "00001"
End If
note.DocNo = LastNo
Messagebox "เลขที่รับเอกสารซ้ำกัน ดังนั้นระบบจะทำการเปลี่ยนแปลงลำดับเอกสารอัตโนมัติไปเป็นเลขที่ " & Cstr(LastNo), 0, "เปลี่ยนแปลง "
End If
End If
End If
[/quote]
ส่วนข้อ 2 ตรง Dim w As New NotesUIWorkspace ประกาศซ้ำ ผมเปลี่ยนเป็น v ได้ไหมครับ
[quote]
Function UDFRepeat(RString As String, Num As Long, Count As Long) As String
On Error Goto Errhandle
AString = ""
For i = 1 To Count - Len(Cstr(Num))
AString = AString & RString
Next
UDFRepeat = AString & Cstr(Num)
Exit Function
Errhandle:
Print "Error in UDFRepeat Function Code : " & Cstr(Err) & " Line : " & Cstr(Erl) & " Description : " & Cstr(Error)
Resume TheEnd
TheEnd:
Repeat = ""
End Function
[/quote]
ตรงนี้ไม่มี error แล้ว
แต่เลขไม่รันให้ครับ คือ เป็นเลข 2009-00001 ตลอดไม่+1 ครับ ผมทำไรผิดปะครับ |