Auto count in a form

  • Thread starter Thread starter Carl J. Hixon
  • Start date Start date
C

Carl J. Hixon

Okay, I am brain dead!

I have a form that stores information about PLCs. Within that form is a
subform that collects information about installed modules. The first field
is a text box that represents the slot number (an integer 1-7, 1-12, 1-24).
Since the numbers are always sequential starting at 1, it seems silly to
type it in. How do I auto insert a number and increment if for each record
of the subform, restarting at 1 each time the parent record changes?

I know that this has to be very simple.

Thanks,
Carl.
 
Okay, I am brain dead!

I have a form that stores information about PLCs. Within that form is a
subform that collects information about installed modules. The first field
is a text box that represents the slot number (an integer 1-7, 1-12, 1-24).
Since the numbers are always sequential starting at 1, it seems silly to
type it in. How do I auto insert a number and increment if for each record
of the subform, restarting at 1 each time the parent record changes?

I know that this has to be very simple.


It's not all that hard. In the BeforeInsert event of the subform put
code like:

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!txtSlot = NZ(DMax("[Slot]", "[tablename]", "[ID] = " & Me!ID)) + 1
End Sub

using your own table and fieldnames of course. ID is the unique
identifier of the PLC (the Child Link Field of the subform).
 
Back
Top