By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,871 Members | 613 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,871 IT Pros & Developers. It's quick & easy.

Button for Manual Serial No generate in MS Access

P: 25
i want to make a button in ms access form for manual data entry serial no.

example

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command984_Click()
  2.     DoCmd.GoToRecord , , acNewRec
  3.     DoCmd.GoToRecord Previous acDataForm, Serial_No = Me.Serial_No.Value + 1
  4. End Sub
how it will be work?

if i entered a data with serial no 1
now going to second serial no 2 by manual clicking a button
so i want to code like go to previous serial no +1 = 2
3 Weeks Ago #1

✓ answered by twinnyfo

Your code would look something like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command984_Click()
  2.     DoCmd.GoToRecord , , acNewRec
  3.     Me.Serial_No = _
  4.         DMax("Serial_No", _
  5.              "YourTableName") + 1
  6. End Sub
Using Domain Aggregate functions (of which DMax() is one of them) is not my favorite, but it should do the job just fine.

Hope this hepps!

Share this Question
Share on Google+
6 Replies

twinnyfo
Expert Mod 2.5K+
P: 3,538
ZKAHADI,

If your serial number is strictly numeric, why not just use the AutoNumber Field that is readily available in MS Access?

This is the easiest way.

However, if there is more behind your question, let us know and we can work with that.

Hope that hepps!
3 Weeks Ago #2

isladogs
Expert
P: 34
Alternatively, if the previous record is the maximum value of that field, you can use =DMax("FieldName", "TableName")+1
3 Weeks Ago #3

P: 25
i dont want to use automatic number because if i delete a record the auto number series gone wrong . for example i entered 5 entries and i delete all then i start from start the auto number starts from 6 not from 1 . and may i start serial no from 100 or others
3 Weeks Ago #4

P: 25
tell me the way how i can use in vba on button .
what i wriate before Equal sign ? =DMax("FieldName", "TableName")+1
3 Weeks Ago #5

twinnyfo
Expert Mod 2.5K+
P: 3,538
Your code would look something like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command984_Click()
  2.     DoCmd.GoToRecord , , acNewRec
  3.     Me.Serial_No = _
  4.         DMax("Serial_No", _
  5.              "YourTableName") + 1
  6. End Sub
Using Domain Aggregate functions (of which DMax() is one of them) is not my favorite, but it should do the job just fine.

Hope this hepps!
3 Weeks Ago #6

Rabbit
Expert Mod 10K+
P: 12,439
It's rarely a good idea to reuse unique identifiers due to future data integrity issues
3 Weeks Ago #7

Post your reply

Sign in to post your reply or Sign up for a free account.