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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subform refresh from combo box on main form 3

Status
Not open for further replies.

ca268339

Programmer
Aug 7, 2000
32
US
I'm trying to refresh a subform based on data contained in a combo box on the mainfrom. In the OnClick property of the combo box I have code that rebuilds the query used by the subform. Essentially I delete the query used as the RecordSource by the subform and then QueryDef the query back again. Once the query is defined, I then try to refresh the subfrom with the following:
Me![My Subform Name].Form.Requery
Me![My Subform Name].Form.Refresh
The query is reset each and every time, but the subform continues to display the same data that was used in the original query used when the form was initially opened. Thanks in advance for any and all help.
 
Requery the object itself that your looking at

Me![My Subform Name].Form.Object.Requery

-Doug


 
Thanks for the response. Isn't the "object" in this case the name of the subform? I've tried a Requery the object with exactly the same syntax as you've suggested

Me![MACD_Count_SF].Form.Object.Requery


And I encounter a run-time error code of 2465. I believe that the 2465 indicates an object-defined error. Correct??

-Doug
 
What if you do the requery in the AfterUpdate event of the combo box? The refresh might not be needed if the requery works right.
 
Still no. On this form/subform combination I have no child/master field relationship. My hope was that I could dynamically change the recordsource that is used by the subform based on the data selected from the combobox. The querydef sets the query attributes just fine, but the subform does not refresh with the new data.
 
Try:

Forms![My Main Form].[My Subform Name].Form.Object.Requery

I think you have to make sure that the "My Subform Name" is the subform control name on the main form NOT the linked form name.

 
Thanks for the last post.

What I forgot was the "Form" descriptor between the object and the subform control name. The code that I used for the subform refresh from a combo box named Combo1 (subform name = test1, subform control name = form1_subform and form=form1)

Code to refresh the subform from the main form combo box:

Private Sub combo1_Click()
Dim sqlstr As String
sqlstr = "select test.field1 from test where ((field1) = " & Me!combo1 & ")"

Forms!form1!form1_subform.Form.RecordSource = sqlstr
Forms!form1!form1_subform.Form.Requery

Refresh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top