For this I ve created a form (say A)separately and store the current sequence no. count in it.
When ever I create a new document I fetch the current value of sequence no. from the form(A) , add one to it and store the new value in form A and also at the place where the id is required.
The problem is if multiple users are present , when they create a new document,they all access this same formA simultaneously to generate the sequence.
Hence this results in duplicate sequence no. generated causing a major flaw in the DB.
there are hundreds of postings about the perils of trying to generate sequential document numbers. And it multiplies exponentially if you have replication. Try some of the better solutions.
Set view = db.GetView("Counter Form view") Set doc = view.GetDocumentByKey("CounterForm")
If doc Is Nothing Then
Set doc = db.CreateDocument
doc.form = "CounterForm"
NumToUse = 1
doc.Counter = Cstr(NumToUse)
Call doc.Save(True, False)
NumToUse = 1
Goto endfun
End If
For i = 1 To 100
NumToUse = Cdbl(doc.Counter(0))
doc.Counter = Cstr(NumToUse + 1)
If doc.Save(False, False) Then
Exit For
End If
Set doc = Nothing
Next
Set view = db.GetView("Counter Form view") Set doc = view.GetDocumentByKey("CounterForm")
If doc Is Nothing Then
Set doc = db.CreateDocument
doc.form = "CounterForm"
NumToUse = 1
doc.Counter = Cstr(NumToUse) ' why store the value as a string, when you need it a number to use it?
Call doc.Save(True, False)
NumToUse = 1 ' already had this value!
Goto endfun
End If
For i = 1 To 100
NumToUse = Cdbl(doc.Counter(0)) ' Object variable not set error, see below.
doc.Counter = Cstr(NumToUse + 1)
If doc.Save(False, False) Then
Exit For
End If
Set doc = Nothing ' 2nd time thru your document will be Nothing! You have to Delete the object and fetch it again.
Next