Please HELP - Subform Maxrecords

  • Thread starter Thread starter Ben Adams
  • Start date Start date
B

Ben Adams

I have an open form that contains a subform. I would like
to restrict the max number of records in the subform.
Using forms(index).maxrecords requirs a string name for
the form.

Any ideas?

Thanks,
Ben
 
I have an open form that contains a subform. I would like
to restrict the max number of records in the subform.
Using forms(index).maxrecords requirs a string name for
the form.

A Subform isn't open in its own right: you need to reference it via
the main form, and the name of the Subform Control in which you have
the subform, e.g.

Forms!mainformname!subformcontrol.Form

I'd suggest using the Subform's BeforeInsert event; use DCount() to
count how many records have already been added to the table and cancel
the insert if there are too many. Counting records displayed on the
subform is problematic since the user could apply a filter to display
fewer records, thereby letting them add more.
 
-----Original Message-----


A Subform isn't open in its own right: you need to reference it via
the main form, and the name of the Subform Control in which you have
the subform, e.g.

Forms!mainformname!subformcontrol.Form

I'd suggest using the Subform's BeforeInsert event; use DCount() to
count how many records have already been added to the table and cancel
the insert if there are too many. Counting records displayed on the
subform is problematic since the user could apply a filter to display
fewer records, thereby letting them add more.


.

I continue to receive an error - it says it can't find form

Forms!mainformname!subformcontrol.Maxrecords = 2
or
Forms(Forms!mainformname!subformcontrol.Form).Maxrecords =
2
 
I continue to receive an error - it says it can't find form

Forms!mainformname!subformcontrol.Maxrecords = 2

I'm not familiar with the maxrecords property... but the likely
problem giving this error is that you need to use the Name property
*of the Subform control* on the mainform, which is not necessarily the
same as the name of the form within that control. For the .maxrecords
property you'ld need to also reference the Form object:

Forms!YourMainFormName!Subformcontrolname.Form.Maxrecords = 2
 
Back
Top