Full Version: auto generated number
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
scsuflyboy
I have a form that I use to create work orders.

Here's what I need help with:

I want to have a field on the form that has a button that when that button is clicked will generate a work order # in the field. I would like to have the work order based on the Month, day, year and work order for that day.


Example: Today is January 17, 2008. If this is the first work order of the day the Work Order # would be:
01170801, if its the second work order of the day it would 01170802, etc...

Any suggestions?
ScottGem
You should have a separate primary key field set to autonumber. I also assume you have another field that stores the date. So what you need to do is add a long integer field named Increment. You would have a hidden control on the form named txtIncrement

The button on your form would use code like:

CODE
Me.txtIncrement = NZ(DMAX("[Increment]","tablename","[WODATE] = #" & Date() & "#"),0)+1
DoCmd.RunCommand acCmdSaveRecord


The DMAx will return the last used Increment for the current date. And then add 1 to it. You then want to save the record before someone else tries to get a WO number.

To display your workorder number you use the expression:

Format([WODATE],"mmddyy" & Format([Increment],"00")
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.