How to limit subform to one record?

M

markmarko

I have certain instances where I need a subform to be able to accept one
record, and no more.

I've been trying setting allowadditions to false if dcount (records for that
mainform record) >0, but I can't get the setup right in terms of which event
to trigger it, etc.

Any advice?
 
J

John W. Vinson

I have certain instances where I need a subform to be able to accept one
record, and no more.

I've been trying setting allowadditions to false if dcount (records for that
mainform record) >0, but I can't get the setup right in terms of which event
to trigger it, etc.

Any advice?

I'd use the Form's (subform's) BeforeInsert event:

Private Sub Form_BeforeInsert(Cancel as Integer)
If Me.Recordcount > 1 Then
MsgBox "Only one record allowed", vbOKOnly
Cancel = True
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