Requery subform

A

alex

I have a subform that’s based on a query. The subform is obviously on
a main form.

When I open the main form, the subform is blank (even though there
should be data).

I have code behind one of my cmdbuttons that requerys the subform.
This works great when the cmdbutton is clicked. Basically I can
requery the subform with an on click event…I want the on load event to
do the same!

How can I requery the subform (so there’s data there) when the form
opens/loads?

I have tried putting:
Me.sfrmMySubform.requery
Or
sfrmMySubform.requery
In every possible place…it does not work.

My thought is, there’s no data in the query (since it’s tied to the
main form) until AFTER the form loads; but I don’t know.

Any thoughts?
alex
 
K

Ken Sheridan

Alex:

Try the parent form's Current event procedure. That way it should be
requeried not only when the form is opened, but also when you navigate to
another record in the parent form. You don't need to repeat the code you've
already written for your button, you can simply call the button's Click event
procedure in the Current event procedure with:

cmdRequerySubform_Click

where cmdRequerySubform is the name of the button. Alternatively you can pt
the code in a function in the form's module and call the function as the
button's On Click event property and the form's On Current event property
(and any other event for which you might need to requery the subform) with
the following in the properties sheet for each:

= RequerySubform()

where RequerySubform is the function's name.

Ken Sheridan
Stafford, England
 
A

alex

Alex:

Try the parent form's Current event procedure.  That way it should be
requeried not only when the form is opened, but also when you navigate to
another record in the parent form.  You don't need to repeat the code you've
already written for your button, you can simply call the button's Click event
procedure in the Current event procedure with:

    cmdRequerySubform_Click

where cmdRequerySubform is the name of the button.  Alternatively you can pt
the code in a function in the form's module and call the function as the
button's On Click event property and the form's On Current event property
(and any other event for which you might need to requery the subform) with
the following in the properties sheet for each:

    = RequerySubform()

where RequerySubform is the function's name.

Ken Sheridan
Stafford, England











- Show quoted text -

Ken,

The form's On Current event worked...
that's probably the only one I didn't try.

Thanks,
alex
 

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

Similar Threads


Top