Limiting rows in subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I am trying to limit the number of rows that may be added to a subform -
e.g. only five orders per invoice. I can get a count of subform rows as each
new one is added - but what is the 'event' in the subform which corresponds
to the user selecting a new row and about to enter data (this is when I want
the code to work)

Thanks

Eddie
 
Once your count = 5, you could set AllowAdditions = False else
AllowAdditions = True..

HTH,
Debbie

| Hi
| I am trying to limit the number of rows that may be added to a subform -
| e.g. only five orders per invoice. I can get a count of subform rows as
each
| new one is added - but what is the 'event' in the subform which
corresponds
| to the user selecting a new row and about to enter data (this is when I
want
| the code to work)
|
| Thanks
|
| Eddie
 
Eddie said:
Hi
I am trying to limit the number of rows that may be added to a
subform - e.g. only five orders per invoice. I can get a count of
subform rows as each new one is added - but what is the 'event' in
the subform which corresponds to the user selecting a new row and
about to enter data (this is when I want the code to work)

The solution I found while playing with this requires a little code in
both the subform and the main form:

'----- start of code for subform's module -----
Option Compare Database
Option Explicit

Public Sub LimitRecords()

Const conRecLimit = 5

With Me.RecordsetClone
If .RecordCount > 0 Then .MoveLast
Me.AllowAdditions = (.RecordCount < conRecLimit)
End With

End Sub

Private Sub Form_Current()

LimitRecords

End Sub
'----- end of code for subform's module -----


'----- start of code for main form's module -----
Option Compare Database
Option Explicit

Private Sub Form_Current()

' *** replace "MySubform" below with the name of the
' *** subform control that displays the subform.

Call Me.MySubform.Form.LimitRecords

End Sub
'----- end of code for main form's module -----

The code simply turns off the subform's AllowAdditions property when the
maximum number of records has been added.
 
Back
Top