Numbering problem

R

Ray

I need to assign a new number to each record as it is entered.
The first record needs to begin with M09-0001 and then go to M09-0002 etc.
What is the best way of doing this?
 
B

BruceM

Assuming you mean for the numbers to start over next year, you could put
something like this in the form's Current event:

Me.YourField.DefaultValue =
Nz(DMax("[YourField]","[YourTable]","Year([DateField]) = " & Year(Date)),0)
+ 1

This assumes there is a date field in the record. Substitute your table and
field names for YourField, YourTable, and DateField.

To display the number you could have this as the control source of an
unbound text box:
= "M" & Format(Date(),"yy") & "-" & Format([YourField],"0000")

You could use the same expression in a query, or in VBA with some minor
alteration. In any case you could test to see if YourField is null, and
leave the text box empty if it is. Details depend on how you approach this.

In a multi-user environment you could place the code in the form's Before
Update event to minimize the chance of a duplicate number if two users
generate a record at the same time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top