Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make a subform update

Status
Not open for further replies.

gxd135

MIS
Jun 18, 2001
41
0
0
US
I have a Main Form with many subforms. One of the subforms runs off a query which contains information based off of the rest of the form. When I change data in the main form, I want the subform to run the query and show me the updated data in real time(without having to refresh the form). I know there are some on focus/on data change controls, but I don't know what to put in them to make this happen. Any ideas are welcome.
 
Assuming your main form is frmMain and your subform is frmMainSubform, then one way of doing this is to place the following line of code in the AfterUpdate event of any controls which would effect the subform's underlying query:

Forms!frmMain!frmMainSubform.Form.Requery

Replace form and subform names above to suit your application. This will force the refresh of the subform whenever any of the controls which affect it change.



Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Do you know of another way I could do it globally, because there are a lot of controls on the form, and I would be putting this in a lot of places? Also do you need brackets around the form names or no? Thanks for the help
 
You only need brackets if you are using a variable to provide the form name. For example, assuming you have a form called frmMain and a control called txtControl, then the following code are the same to display the value of the control:

msgbox Forms!frmMain!txtControl

and

YourForm = "frmMain"
YourControl = "txtControl"
msgbox Forms(YourForm)(YourControl)

and

msgbox Forms("frmMain")("txtControl")

To do the above globally would be a bit more tricky if you wanted to see the effect each time you changed a related control. If seeing the effect instantly wasnt important, you could have a single button next to the subform, and then refresh the subform on the button click event.

Alternatively, you might display the associated subform on a second page of a tab control, then use the page change event to recognise when you move to the page, and when this happens, do the requery.

HTH

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top