Link to home
Start Free TrialLog in
Avatar of Wadley1957
Wadley1957

asked on

Update a form's data output by changing the query to which it's bound without closing/reopening form

Hi. I have a form "frmHST"  that opens from another form. frmHST's source data is a Select Query generated by user field selections on that source form where a little VBA code organizes into a QueryDef, providing the data set for frmHST which it then opens. While still open, I would like the user to have the option of generating a new queryDef from within frmHST and regenerate the form based on these new data. The code for revising the query is easy. How do I cause frmHST to display data based on the revised query. Refresh? Requery? Thanks
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can do a test if the form frmHST is already loaded

if currentproject.allforms("frmHST").isloaded then
      Forms!frmHST.requery
      else
      docmd.openform "frmHST"
end if
Avatar of Wadley1957
Wadley1957

ASKER

Thanks for your fast response!
me.recordsource = SQLStringVariable worked! However, the form, frmHST is a subForm (continuous) that displays the filtered records, contained in a main form which has textBoxes where "=Sum()" functions summarize the subform data. How can I set the record source of the subform?
Let's say the main form is "frmHST" and the subform is "sFrmHST"
Wadley1957,

<the form, frmHST is a subForm (continuous) >

you should have mentioned this in your original post.

Yes. I see that I should have.
So, to clarify, frmHST is a form that contains subform sFrmHST. Both have the same source data, queryDef, "qtyTEMP". Initially, frmHST is opened from yet a third form, frmMain. frmMain has a button, cmdLookUp that creates the queryDef using the "LIKE * & myField & *" string to establish the underlying data set for frmHST which it then opens.
My intention is to give the user the opportunity to type another, substitute myField string to try the query again, only to do this directly from frmHST. The info being sought, here, may require the user's intuition and my require several "best guess" attempts before hitting on the correct item.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Very fast and accurate responses. Thanks!