Name#? error driving me crazy

  • Thread starter Thread starter John Egan
  • Start date Start date
J

John Egan

I have a form, "JobCardForm" to enter data into a table "JobCard". I want to
automatically increment the "JobNumber" field in this table. I thought I
could just put a function in the default value of the form control for
JobNumber.
I have entered =DMax(["JobNumber"],["JobCard"])+1 into the default value
field in the control box for JobNumber in the JobCardForm. When I go bact to
use the form and try to enter a new record I get the Name#? error in the box
for JobNumber. Any help please.

John
 
I have a form, "JobCardForm" to enter data into a table "JobCard". I want to
automatically increment the "JobNumber" field in this table. I thought I
could just put a function in the default value of the form control for
JobNumber.
I have entered =DMax(["JobNumber"],["JobCard"])+1 into the default value
field in the control box for JobNumber in the JobCardForm. When I go bact to
use the form and try to enter a new record I get the Name#? error in the box
for JobNumber. Any help please.

John

You've got your quotes and your brackets inside out for one thing!

Instead of using the default value, I'd suggest using the Form's
BeforeInsert event:

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!JobNumber = NZ(DMax("[JobNumber]", "[JobCard]")) + 1
End Sub
 
Back
Top