damixa
asked on
Lotus Notes Programming
I have a form where i have a field as number.
I want to fill this field automatically every time i create a new form. It should be filled in an incremental order. noofforms+1
thanks
I want to fill this field automatically every time i create a new form. It should be filled in an incremental order. noofforms+1
thanks
or make use of this.....
In the QuerySave event of the form, get the highest numbered existing document and set the number on the document being saved:
dim sess as new NotesSession
dim db as NotesDocument
dim ws as new NotesUIWorkspace
dim uidoc as NotesUIDocument
dim doc as NotesDocument
dim viewLU as NotesView
dim docLU as NotesDocument
dim docno as Long
set db = sess.CurrentDatabase
set uidoc = ws.CurrentDocument
set doc = uidoc.Document
set viewLU = db.GetView("ByNumberView")
set docLU = viewLU.GetFirstDocument
if docLU is Nothing Then
'*** No documents in view; this one is #1
call doc.ReplaceItemValue("DocNumber", 1)
else
'*** Get the current highest number
docno = docLU.GetItemValue("DocNumber")(0)
docno = docno + 1
call doc.ReplaceItemValue("DocNumber", docno)
end if
call uidoc.Refresh
ASKER
I get in both cases
object variable not set...
object variable not set...
You created the view that's used by the code?
Also, try debugging the code and check in which line it is giving error.
Make sure the view exists.
Make sure the view exists.
ASKER
The view is created as above, for the first example i get the variable not set immediately in the variable declaration, in the second example the code can not be compiled because there is a code error. in the variable declaration. db you have declared as a document and you set a database in the declaration, ??
can it be there the error. thanks
can it be there the error. thanks
Incremental numbering is very difficult to do properly,
especially under the following conditions.
1) Multiple users working simultaneously
2) multiple servers
Preferable options are to use a random ID via Unique or via the Doc ID.
I hope this helps !
especially under the following conditions.
1) Multiple users working simultaneously
2) multiple servers
Preferable options are to use a random ID via Unique or via the Doc ID.
I hope this helps !
Try below code....
Sub Initialize
Dim s As New notessession
dim ws as new notesuiworkspace
dim uidoc as notesuidocument
set uidoc=ws.currentdocument
Dim doc1 As notesdocument
Set doc1 = uidoc.document 's.documentContext
'If(doc1.ISNEWNOTE) Then
if uidoc.isnewdoc then
Dim view1 As notesview
Dim db1 As notesdatabase
Set db1 = s.currentDatabase
Set view1 = db1.getView("SequenceNo") 'View Name and it should be in Descending order
Dim doc2 As notesdocument
Set doc2 = view1.getFirstDocument
Dim incrementNumber As Integer
if not doc2 is nothing then
incrementNumber = Cint(doc2.SequenceNo(0)) + 1 'SequenceNo is the field name on the form which stores the Sequence no.,.
'doc1.Contactlog = Cstr(incrementNumber)
'doc1.LoggedBy=""
doc1.SequenceNo = Cstr(incrementNumber)
Call doc1.save(False, True)
else
doc1.SequenceNo = "1" 'Cstr(incrementNumber)
Call doc1.save(False, True)
end if
End If
End Sub
ASKER
OK from your code i understand that you assume the field is text, well when is text the field than there comes the error variable not set, if i change the field to number than the error doesnt show up.i think im doing something wrong here.
i have the view called sequenceno (in descending order), i have a form with a field as text or number thats all i have, and i have your code in the initialize event in the form...
what i wanted is when i create the form the incremented number you have coded comes to the sequence field.
i have the view called sequenceno (in descending order), i have a form with a field as text or number thats all i have, and i have your code in the initialize event in the form...
what i wanted is when i create the form the incremented number you have coded comes to the sequence field.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks great help works perfect,
Open in new window