Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DMax with Criteria

Status
Not open for further replies.

WallT

Vendor
Aug 13, 2002
247
US
I have a SubForm that I am trying to use DMax to automatically generate multple consecutive locationNumbers on the SubForm for each OrderNumber on the MainForm.

Private Sub Form_BeforeInsert(CANCEL As Integer)

Me.LocationNumber = DMax("[LocationNumber]", "TBLLocations", "[OrderNumber] =" & [OrderNumber]) + 1

End Sub

I keep getting an invalid syntax error...where does it appear I am going wrong on this.
 
Okay I think I am almost there if I can just get a little help. I changed it to the following, but when I am puting in a brand new record, it places 1 as the first location, but then when I tab to another field it make makes my LocationNumber Null.???

Private Sub Form_BeforeInsert(CANCEL As Integer)

Me.LocationNumber =
Nz(DMax("[LocationNumber]", "TBLLocations", "[OrderNumber] =" & [OrderNumber]), 0) + 1

End Sub
 
Wow, I did this one myself...never mind. I had contradictory code in another field I had tried earlier and never deleted...oops!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top