Action based on subform record count

G

Guest

Here's my dilemma.

I have three tables (Audits, Audit Results, Audit Scores). My main form
(based on Audits) has two subforms (AuditResults subform and AuditScores
subform).

When a user enters info into the main form, the subforms are both empty.
The AuditResults subform is populated by a query.

I want the button that launches this query to be enabled as long as the
AuditResults subform is empty. But, if the user opens the record at a later
date, I want the button to be disabled (preventing the user from accidentally
populating a 2nd set of records).

How do I check the subform and get a record count? Currently, I use the an
indepentend form with a field set to the following:
=Forms!Audits![AuditResults subform].Form.Count

I emptied all three tables and entered 1 set of records and this subform is
returning 22 (it should be returning 8).

Any ideas?
 
T

tina

I want the button that launches this query to be enabled as long as the
AuditResults subform is empty. But, if the user opens the record at a later
date, I want the button to be disabled (preventing the user from accidentally
populating a 2nd set of records).

if i understand correctly, this command button is on the main form. so in
the main form's Current event procedure, try the following code, as

Me!MyCommandButton.Enabled = Not
(Me!MySubformControlName.Form.Recordset.RecordCount > 0)

the above should all be on one line. and substitute the correct control
names, of course.
put the same code in the Exit event procedure of the subform *control*.

note: make sure you're referring to the name of the subform *control*, NOT
the name of the subform object as it appears in the database window
(sometimes the two names are identical, but sometimes they're different). to
make sure you get the correct name:
1. open the main form in design view.
2. click once on the subform (within the main form) to select it.
3. open the Properties box and click on the Other tab.
4. look at the Name property. that's the name of name of the subform
control.

you don't need that independent form that you mentioned using.

hth


Robert_L_Ross said:
Here's my dilemma.

I have three tables (Audits, Audit Results, Audit Scores). My main form
(based on Audits) has two subforms (AuditResults subform and AuditScores
subform).

When a user enters info into the main form, the subforms are both empty.
The AuditResults subform is populated by a query.

I want the button that launches this query to be enabled as long as the
AuditResults subform is empty. But, if the user opens the record at a later
date, I want the button to be disabled (preventing the user from accidentally
populating a 2nd set of records).

How do I check the subform and get a record count? Currently, I use the an
indepentend form with a field set to the following:
=Forms!Audits![AuditResults subform].Form.Count

I emptied all three tables and entered 1 set of records and this subform is
returning 22 (it should be returning 8).

Any ideas?
 

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