Requery on sub-form (datasheet)

  • Thread starter Thread starter Wayne Robinson
  • Start date Start date
W

Wayne Robinson

I have a main form on which a user selects a tax topic that then selects
state details for that topic. On this form I allow a user to click a button
to add a record. This action brings up a new form. Once the record is saved
and the form closed, the user goes back to the details form.

What I am interested in doing is having the details sub-form
refresh(requery). I have SubForm.requery in the GotFocus event but it does
not work. Only hitting F9 can I get the requery to work. I know there must
be a way, but I am not proficient in VBA at this point and could use any
advice.

Kindest regards,
Wayne
 
Hi Wayne,

I ran into this a while back as well, and while it probably isn't the best
way, here is what I did.

Because you stated that you had a button that the users clicked on to add a
new record, make that form modal. That way they will have to Cancel or Save;
no option.

Then, on your main form with the button that the user clicked on to enter
the new record, create a GotFocus event for your button. Since I don't know
where you are with VBA, forgive me for stating any sample code that is
obvious...

SAMPLE CODE:
==========
Private Sub cmdMyButton_GotFocus()
subMySubFormName.Requery
End Sub

I hope that this works for you. The idea is that you "guide" your user into
making the decision to either enter a new record or not. Regardless of that
decision, you will force a requery of the subform through the button, not the
subform itself.

Good luck and let me know if I haven't explained this well enough.

Lance
 
Thanks Lance, it works!

Why does that work and not the focus on the form? Is it just the way it is?

Regards,
 
Thanks Lance it worked. Don't know why vs. gotfocus on the form.
 

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

Back
Top