Numbers generates form fields

I want to generate a number from the field authomatically when i open the form for example

Status Number: 000-000-01

                    000-000-02

like this.

please help…

thanks i appreciate all help for that kind of situation

Subject: numbers generates form fields

First keep in mind: Sequential numbers are not recommended for databases used locally wihtout server connection (possibility of double entries).If create the number in advance and the document won’t be saved, the number is lostWith this solution then the number will be created while first saving.

Else it’s quite easy:

1.) Create a counter document with the fields:

-Form = “CounterDoc”

-Field = “StatNumber” (Number field - Initial value = 0)

-Field = “Authors” (Author Field - Initial value = “*”)

→ Create a document with the counter form and save it.

2.) Create a new view:

-View Name= “Lookup StatNum|lkpStatNum”

  • Selection = SELECT Form=“CounterDoc”

-1. Column-Formula = “StatNum” (This column must be sorted ascending)

-2. Column-Field = StatNumber

→ you should see there the created document from Step 1.

3.) Add this script to the querysave of your document:

Dim nss As NotesSession

Dim docNum As NotesDocument, doc As NotesDocument

Dim nvw As NotesView



Set doc = source.document

If Cstr(doc.StatNumber(0)) = "" Then

	'already numbered

Else

	'Adjust Number and save

	Set nvw = nss.CurrentDatabase.GetView("lkpStatNum")

	Set docNum = nvw.GetFirstDocument

	docNum.StatNumber = docNum.StatNumber(0) + 1

	Call docNum.Save(True,False,True)

	

	doc.StatNumber = docNum.StatNumber(0)

	If source.EditMode Then Call source.Refresh

End If
  1. Create 2 Fields in your document:

Field1 = “StatNumber” (Number field, editable)

Field2 = “DispNumber”

→ Computed for display

→ Formula is

_vNum := @Right(“000000000”+@Text(StatNumber);9);

@If(StatNum=“”;“Please save the document”;@left(_vNum;3)+“-”+@Middle(_vNum;3;3)+@Right(_vNum;3))

Subject: RE: numbers generates form fields

thanks for the help…thank you very much…

To All

Subject: RE: numbers generates form fields

encouter an error type mismatch what shall i do…

i change the stanum into employeeid…

Subject: RE: numbers generates form fields

it seems that the employee id is a text field. then you have to change the script to convert the text to a number first

Subject: numbers generates form fields

Use the Postopen event of the form and add hereDim doc as NotesDocument

dim statnumstr as String

Dim statnum as Double

set doc.Source.Document

statnumstr = doc.GetItemValue(“StatNum”)(0)

statnum = CInt(Left(statnumstr, 3)) * 100000 + CInt(Mid(statnumstr, 5, 3)) * 100 + CInt(Right(statnumstr, 2))

statnum = statnum + 1

statnumstr = Format(statnum, “00000000”)

statnumstr = Left(statnumstr, 3) + “-” + Mid(statnumstr, 4, 3) + “-” + Right(statnumstr, 2)

call doc.ReplaceItemValue(“StatNum”, statnumstr)

PS: In some versions the Format function does not give the expected result. You could use this function instead:

Function MyFormat(i As Double, ilen As Integer) As String

MyFormat = Right$(String$(ilen, "0") + Cstr(i), ilen)

End Function

Invoke is as: statnumstr = MyFormat(statnum, 8)

Subject: RE: numbers generates form fields

Encounter an error to this code

Dim doc as NotesDocument

dim statnumstr as String

Dim statnum as Double

set doc.Source.Document ---------- error of this line

statnumstr = doc.GetItemValue(“StatNum”)(0)

statnum = CInt(Left(statnumstr, 3)) * 100000 + CInt(Mid(statnumstr, 5, 3)) * 100 + CInt(Right(statnumstr, 2))

statnum = statnum + 1

statnumstr = Format(statnum, “00000000”)

statnumstr = Left(statnumstr, 3) + “-” + Mid(statnumstr, 4, 3) + “-” + Right(statnumstr, 2)

call doc.ReplaceItemValue(“StatNum”, statnumstr)

PS: In some versions the Format function does not give the expected result. You could use this function instead:

Function MyFormat(i As Double, ilen As Integer) As String

MyFormat = Right$(String$(ilen, “0”) + Cstr(i), ilen)

End Function

Subject: RE: numbers generates form fields

Oh, good Lord. Please do not tell me that you actually put this line in the code:

PS: In some versions the Format function does not give the expected result. You could use this function instead: