how to limit records in subform??

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

Guest

1.i am using one-to-many relationship.my main form contain subform and i want
to limit my subform record to 14 records only.after all records filled by
user, the system will move to next record in main form.(1 form = 14 records)
 
1.i am using one-to-many relationship.my main form contain subform and i want
to limit my subform record to 14 records only.after all records filled by
user, the system will move to next record in main form.(1 form = 14 records)

You can put code in the BeforeInsert event of the subform using
DCount() to count how many records are in the table with the current
form's master link field value. Without knowing more about the
structure of the tables, I can't be specific, but it would be
something like

Private Sub Form_BeforeInsert(Cancel as Integer)
If DCount("*", "[tablename]", "[Keyfield]=" & Me!Keyfield) > 14 Then
Cancel = True
MsgBox "14 records entered, moving on", vbOKOnly
Parent.SetFocus
DoCmd.GoToRecord acForm, Parent.Name, acNewRecord
End If
End Sub

John W. Vinson[MVP]
 
Back
Top