Line Numbers

Hi AceBK,

On the before insert of your subform:

Code:
Private Sub Form_BeforeInsert(Cancel As Integer)

Me.LineNumber = Nz(DMax("LineNumber", "tb_OrderRequestDetails", "OrderRequest_ID = " & Forms![Order Request Menu]!ID), 0) + 1

End Sub

LineNumber is where you want to automatically update the sequential number per order.

tb_OrderRequestDetails is the domain where the LineNumber is located.

OrderRequest_ID is the foreign key that linked on the Primary Key in the Main Form

Forms![Order Request Menu]!ID is how you will reference the primary key in the main form.

What it means is find the largest number on the tb_OrderRequestDetails where the ID of the tb_OrderRequestDetails is equal to the ID of the Main OrderRequest. If the value is 0 or null, replace it with 1, then increment the value as you insert new record on the subform.

Hope it helps.
 

Users who are viewing this thread

Back
Top Bottom