Not allow more than 3 records in subform

J

Joel Levy

TWIMC:
TIA:

Trying to not allow additional records to subform if there
are currently 3 records (ie no more than 3 records allowed
in subform).

Any ideas??

Thanks again,
Joel
 
A

Allen Browne

Cancel the BeforeInsert event of the form:

Private Sub Form_BeforeInsert(Cancel As Integer)
If Me.RecordsetClone.RecordCount >= 3 Then
Cancel = True
MsgBox "No more records!"
End If
End Sub
 
J

JohnFol

You could check for .recordcount >3 and abort the update, or only allow
editing to begin if recordcount<3
 
J

Joel Levy

Allen:

Thanks so much.

Joel
-----Original Message-----
Cancel the BeforeInsert event of the form:

Private Sub Form_BeforeInsert(Cancel As Integer)
If Me.RecordsetClone.RecordCount >= 3 Then
Cancel = True
MsgBox "No more records!"
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.




.
 
G

Guest

Allen:

had to add to If statement ...And form.newrecord=True Then

Otherwise couldn't edit any record if count was 3!!

Thanks, Joel
 
T

TC

Evil TC says:

- filter to record #1 (via PK or whatever);
- add new record;
- add new record;
- re-filter to record #1;
- add new record;
- add new record;
etc!

I'd be saying, if Me.FilterOn then msgbox "Sorry, you must remove the filter
before you add a new record", etc.

Cheers,
TC
 

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