Limit Rows In Subform to one row only.

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

Guest

Hello
Is there is a way to limit the number of rows in a subform to one.

Thank you and best regards
 
you could try the following in the subform's Current event procedure, as

Me.AllowAdditions = Not (Me.RecordsetClone.RecordCount > 0)

hth
 
Try using "SELECT TOP 1... " SQL statment as recordsource for your subform.
Look at Access help for sintax

Rocco
 
Hello Tina Thank you for your reply.
This works fine for only the first record of the main form. If you navigate
to another record of the main form. The allowadditions on subform is set to
false.
How to reset it back to true , when you change record in the main form

Thank you and best regards
 
Thank you for your reply.
But the subform is linked to a table not a query. Thus select will not work.
 
You can use a SQL statment as RecordSource for your subform.
Assume it takes records from a table named "YourTable"

You can set the recordSource of your subform to:
SELECT * FROM YourTable WHERE...

In the WHERE clause, you can arrange the condition to retrive the record you
want, if any.

Hope this help.
Rocco
 
hmm, ok. try this: leave the code on the subform that i gave you
previously. add the following code to the *main* form's Current event, as

With Me!NameOfSubformControl.Form
.AllowAdditions = Not (Me.RecordsetClone.RecordCount > 0)
End With

note: make sure you use the name of the "container" subform control in the
main form, *not* the name of the subform object as you see it in the
database window. sometimes the names are the same, but sometimes they're
not. to get the correct name to use in the line of code above: open the
main form in design view. click *once* on the subform (within the main form)
to select it. in the Properties box, click the Other tab and look at the
Name property.

hth
 
Bassel, note that rocco and i are each explaining how to meet two
*different* objectives, and neither one of us knows which one you actually
want.

i'm explaining a solution that let's you *enter* one new record in a subform
if there are no records already existing for the current record in the main
form, but does *not* allow entry of a new record in the subform when there
is already one or more records displayed in the subform.

rocco is explaining a solution that displays only one record in the subform
for the current mainform record, regardless of how many related subform
records exist. i don't think it limits data entry in the subform (in other
words, i don't think that the query is a "non-updateable" query) but i'm not
sure - rocco could tell you for sure.

as you can see, two very different solutions. depending on what you're
actually trying to accomplish, you may need one, or both, or neither. i just
want you to be clear on what you're "getting" from us.

hth
 
Back
Top