Automatically increase Order Number

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've created a form to enter orders into. I figured out how to use the
autofill function so that each new record pulls the number from the previous
record. But what i want to do is have the order number automatically filled
in, but increased by one. How can this be done?
 
This is probably the roughest code around but I know it works. I have it
behind a button 'New Form' on a form.

Dim refvar As Integer
Dim mydate

DoCmd.Echo False
DoCmd.Requery

DoCmd.GoToRecord , , acLast 'go to last record in table
refvar = REFERENCE + 1 'add 1 to reference
DoCmd.GoToRecord , , acNewRec 'append new record to table
REFERENCE = refvar 'fill in refence
mydate = Now() 'remember today's date
Me![refdate] = mydate 'fill in refdate with todays date
refdate.SetFocus 'set focus on refdate

'save the new record
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

DoCmd.Echo True
 

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

Back
Top