How can I have consecutive numbers in Access

B

Bipbop

I have used this Event Procedure in Before Insert:

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!textboxname = NZ(DMax("TraineeID", "Trainees")) + 1
End Sub

But it doesn't work and I don't understand why?

I also tried:

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!Trainee ID = NZ(DMax("TraineeID", "Trainees")) + 1
End Sub

What am I doing wrong?
 
R

Rick Brandt

Bipbop said:
I have used this Event Procedure in Before Insert:

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!textboxname = NZ(DMax("TraineeID", "Trainees")) + 1
End Sub

But it doesn't work and I don't understand why?

Is textboxname just and example here? Is that the actual name of the TextBox?
I also tried:

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!Trainee ID = NZ(DMax("TraineeID", "Trainees")) + 1
End Sub

What am I doing wrong?

If a field name has a space in it then you need square brackets around it.

Me![Trainee ID] = NZ(DMax("TraineeID", "Trainees")) + 1

....but since you don't show a space in the name in the DMax() function then I
have to ask which spelling is correct? They should agree.
 

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