keys in a detail table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have generally followed the practice of keying a detail table in a simple
header, detail structure with the header key and a line or record number.
For an orders application, for instance, the order detail table would have
the order number and the order line number as keys. I don't want to use the
auto number field type for the line number, because I want the lines to start
at 1 for each new order. Since Access doesn't have a specifice record level
event, where do I place the code to increment the counter? How do you keep
it from firing everytime a control in the current record is updated?

DM
 
Dick said:
I have generally followed the practice of keying a detail table in a simple
header, detail structure with the header key and a line or record number.
For an orders application, for instance, the order detail table would have
the order number and the order line number as keys. I don't want to use the
auto number field type for the line number, because I want the lines to start
at 1 for each new order. Since Access doesn't have a specifice record level
event, where do I place the code to increment the counter? How do you keep
it from firing everytime a control in the current record is updated?


The code for this would go in the form's BeforeInsert event.

To increment the detail line number, you can use the DMax
function something like this:

Me.LineNum = Nz(DMax("LineNum", "OrderDetails", _
"OrderID = " & Me.OrderID), 1)
 
Back
Top