Solved

Lotus Notes Programming

Posted on 2007-11-28
11
219 Views
Last Modified: 2013-12-18
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
0
Comment
Question by:damixa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 19

Expert Comment

by:madheeswar
ID: 20364125
Please use below code:

Sub Initialize
Dim s As New notessession
Dim doc1 As notesdocument
Set doc1 = s.documentContext
If(doc1.ISNEWNOTE) 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
incrementNumber = Cint(doc2.SequenceNo(0)) + 1
doc1.Contactlog = "CN"+Cstr(incrementNumber)
'doc1.LoggedBy=""
doc2.SequenceNo = Cstr(incrementNumber)
Call doc2.save(False, True) 
End If
 
End Sub

Open in new window

0
 
LVL 19

Expert Comment

by:madheeswar
ID: 20364131
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

Open in new window

0
 

Author Comment

by:damixa
ID: 20364408
I get in both cases
object variable not set...
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 20364961
You created the view that's used by the code?
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 20364965
Also, try debugging the code and check in which line it is giving error.
Make sure the view exists.
0
 

Author Comment

by:damixa
ID: 20365335
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
0
 
LVL 63

Expert Comment

by:SysExpert
ID: 20370969
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 !
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 20371687
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

Open in new window

0
 

Author Comment

by:damixa
ID: 20372209
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.
0
 
LVL 19

Accepted Solution

by:
madheeswar earned 500 total points
ID: 20372249
Sorry for that. I did not saw the INitialize event.
Place the below code in the QuerySAve event. We need to generate the sequence number when the document is saved. In this way, we have the correct sequence numbers.
As for SequenceNo  field, it can be a text.
Best of Luck
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

Open in new window

0
 

Author Comment

by:damixa
ID: 20372425
thanks great help works perfect,
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question