How would I go about generating and displaying an automatic and distinct work order number each time a form is opened and before the information is saved to a table?
If you don't want to use the Autonumber feature then you will have to create a permanent variable to store a value that can be read by your form every time it opens and updated every time you save a record with the current value as an ID.
Here are a few ideas to get you going. The names are suggestions of course.
Create a table called: tblValues
Add a field called: RecNum
type: autonumber
required: Yes
allow duplicates: No
validation rule: = 1
This will create a table with one record which you can populate with as many permanent variables as you need.
Add a field called: intIncrement
type: Long Integer
Save the table.
In the header of your form's code module add: Dim UniqueID As Long
The following code will increment the value held in the intIncrement field in tblValues. If you use a command button to Save the record then you could place the code in the button's Click event.
DoCmd.RunSQL "UPDATE tblValues SET " _
& "tblValues.intIncrement = [intIncrement]+1" _
& " WHERE (((tblValues.RecNum)=1));"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.