Help with this SubForm Please

S

Shadow

How can I restrict the number of registering data in a subform?

I have a main form(frmCustomers). There's a subform(frmOrders) in this main
form that is used to input the orders. Both forms are linked with a ID field
base on a One-to-many relationship.
I have to restrict the user of this form to register only 7 orders in the
subform. If he wants to register more, he has to go to the next record on
the main from.

I appreciate any kind of help.

Ghalamkari
 
A

Allen Browne

Cancel the Before Insert event of the subform.

The Event Procedure will look like this:

Private Sub Form_BeforeInsert(Cancel As Integer)
If Me.RecordsetClone.RecordCount >= 7 Then
Cancel = True
MsgBox "Start a new order."
End If
End Sub
 
J

John Smith

I would suggest that :-

If Me.RecordsetClone.RecordCount < 7 Then
AllowAdditions = True
Else
AllowAdditions = False
End If

You may have to experiment with where you do this to ensure that Access has not
already moved to a new record that you are attempting to disallow. The Current
or BeforeUpdate events of the subform would seem likely possibilities.

Good Luck!
 

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