Subform - Line Numbering

G

Guest

I need help - it almost works. I have a form [orders] with a subform [orderdetails]and need to have a lineitemno on each record for the order details.
From this forum (yea!) someone helped with the following code - but it always brings lineitemno to 1 - never increases as I add orderdetails. I have debugged (put a toggle point) and the new record is in the table with the lineitemno as 1 - so I am lost. I feel it must be something with the quotes but I can't get it run any other way.

Private Sub Form_BeforeInsert(Cancel As Integer)
Me![txtLineitem] = Nz(DMax("[LINEITEMNO]", "orderdetails", [ORDERNO] = " &Me![ORDERNO]")) + 1
End Sub

All help is greatly appreciated as I have spent 2 days with this already.
Thanks
 
D

Douglas J. Steele

Your quotes are wrong for the 3rd parameter

Me![txtLineitem] = Nz(DMax("[LINEITEMNO]", "orderdetails", "[ORDERNO] = " &
Me![ORDERNO])) + 1


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Pdehner said:
I need help - it almost works. I have a form [orders] with a subform
[orderdetails]and need to have a lineitemno on each record for the order
details.
From this forum (yea!) someone helped with the following code - but it
always brings lineitemno to 1 - never increases as I add orderdetails. I
have debugged (put a toggle point) and the new record is in the table with
the lineitemno as 1 - so I am lost. I feel it must be something with the
quotes but I can't get it run any other way.
Private Sub Form_BeforeInsert(Cancel As Integer)
Me![txtLineitem] = Nz(DMax("[LINEITEMNO]", "orderdetails", [ORDERNO] = " &Me![ORDERNO]")) + 1
End Sub

All help is greatly appreciated as I have spent 2 days with this already.
Thanks
 

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

Similar Threads

Defining field for subform 1
Increment "text" not number 2
help with code on event call 3
Number of labels to print 2
Adding Field Data In A New Subform row 2
run-time error 3075 1
Invoice Numbering 4
Auto Number 5

Top