cwbarrett
asked on
Requery a subform
I have a form with 3 subforms. There is no recordsource in the main form. Subform Master/Child links are linked to text boxes in the main form.
In general, when I select a record in subform 1, subform 2 updates to show a new set of records based on my subform1 selection. I then select certain records in subform2 via a checkbox in each record then run an append query via a Button On-click Event to add the records to the table in subform3. Everything works fine except I cannot requery subform3 to show the new records. Access does not like my Requery commands any way I put them.
(if I exit the form then re-open the records are there).
Can someone please help with a VBA or macro to update subform3. Current focus is subform2 but I want to requery the records in subform3 using a macro or VBA.
Help is much appreciated.
Charlie
In general, when I select a record in subform 1, subform 2 updates to show a new set of records based on my subform1 selection. I then select certain records in subform2 via a checkbox in each record then run an append query via a Button On-click Event to add the records to the table in subform3. Everything works fine except I cannot requery subform3 to show the new records. Access does not like my Requery commands any way I put them.
(if I exit the form then re-open the records are there).
Can someone please help with a VBA or macro to update subform3. Current focus is subform2 but I want to requery the records in subform3 using a macro or VBA.
Help is much appreciated.
Charlie
ASKER
Thanks for replying, your help is most appreciated. You did reveal my problem. I was executing the code from a subform2 button. When I used your code format and placed the button & code in the "form1" form it worked fine.
Is there any way of executing this code from the subform form2 ? or does code to requery subform3 have to run from form1, the main form?
THANK YOU!
Is there any way of executing this code from the subform form2 ? or does code to requery subform3 have to run from form1, the main form?
THANK YOU!
You can use:
Me.Parent!NameOfSubformCon trol3.Requ ery
or:
Me.Parent!NameOfSubformCon trol3.Form .Requery
/gustav
Me.Parent!NameOfSubformCon
or:
Me.Parent!NameOfSubformCon
/gustav
Both forms are fine for Requery, but to reference other controls, you need to use the second format:
Debug.Print Me.Parent!NameOfSubformCon trol3.Form .ControlNa me
Debug.Print Me.Parent!NameOfSubformCon
ASKER
Worked great, thank you.
Charlie
Charlie
You are welcome!
/gustav
/gustav
ASKER
I get stuck on the easiest things... In subform1 I want to run a query whenever there is a record selection change (I move from one record to the next) in the detail area. Common sense tells me the "On Selection Change" event could trigger this but it doesn't. Can you tell me how to run a query whenver I select a different record in the detail area?
Thanks
Thanks
It's the OnCurrent event.
/gustav
/gustav
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OnCurrent executed the code but it was a never ending loop that executed the code over and over. Had something to do with the Master/Child link so I removed the Master/Child link in this subform1 and changed the datasource from a query to an SQL select query with criteria that was formerly part of the Master/Child link. My form seems to be working fine now.
Thanks again.
Thanks again.
ASKER
I didn't notice the other comment. Where is the upload? I would like to see what you did, it may work better for me.
Thanks
Thanks
ASKER
Oh. Thought you posted another.
Thanks
Thanks
No, it's in that one. You'll see "hidden textbox" on the main form, meaning that in real application it would be with Visible=False. It takes the value from the subform1, and then it serves as the parent for subform2.
ASKER
Thank you!
db.mdb