Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

subform to allow only five records

Access 2010 vba:

I'm trying to limit the numbers of records to enter into a subform.
The forms main "current event".
I have:
With Me![dbo_t_redbook_pricing_escalation_detail_subform].Form
  If .Recordset.RecordCount <= 5 Then
    .AllowAdditions = True
    .AllowEdits = True
  Else
    .AllowAdditions = False
    .AllowEdits = True
  End If
End With

Open in new window


But I never get prompted to stop any data entry beyond 5 records ?

Thanks
fordraiders
Avatar of Fordraiders
Fordraiders
Flag of United States of America image

ASKER

I found this bit of code and it works great.
Public Function LimitRecords( _
          frm As Access.Form, _
          Optional RecLimit As Integer = 1)
 
  ' Limit the number of records in the form passed as
  ' to no more than the number specified by .
 In a module:
  With frm.RecordsetClone
    If .RecordCount <> 0 Then .MoveLast
    frm.AllowAdditions = (.RecordCount < RecLimit)
  End With
End Function

Open in new window


Called by

LimitRecords Me, 5

But Just need some stop message when trying to enter a 6th record. Or Some Alert.
Thanks
fordraiders
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanx very much !
You are welcome!

/gustav