how to limit records in subform??

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)
 
J

John Vinson

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]
 

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

Top