Combo Box & Subform

J

John

Running A2000

Can you use a combo box to pull data into a subform from a query?

I have a combo box, cboMonth, that shows a month of the year. When
the user selects the month then the subform will show the information
for that month from a query. The query has an expression that pulls
the month from combo box. The information in the subform is just
going to be 5 text boxes that will have summary info in them.

Thanks,

John
 
J

JohnR

Yes.

I assume that the query is being used to populate the
subform. In the query, set the criteria for the month to
Forms!YourMainFormName!YourComboBoxName substituting the
names of your form and combobox. Then in the combobox
create an OnChange event procedure that requeries the
data.

Forms!YourMainFormName.form!YourSubFormName.Requery
 
J

John

I have tried that but I got an error that said "Compile Error: Variable Not Defined"

I feel like I am missing something else. If I go from view mode to design mode after selecting a month and then back to view mode it will show the correct info in the subform.

John

----- tina wrote: -----

set the AfterUpdate event of the combobox to

SubFormControlName.Requery

hth
 
J

John

John

I tried that and it still didn't work. Here is what I had in the code for the combo box

Private Sub cboMonth_AfterUpdate(
Forms!Test_Monthly_Summary.Form!sbfrmQuery_All_Money.Requer
End Su

I also tried it as cboMonth_Change() like you mentioned and it still didn't work

In my query I have an expression that normally prompts the user for the month. Expr1: Month(trans_date) In the criteria I have the following: [Forms]![Test_Monthly_Summary]![cboMonth] This is where the combo box passes the month to the query for the subform

Joh

----- JohnR wrote: ----

Yes

I assume that the query is being used to populate the
subform. In the query, set the criteria for the month to
Forms!YourMainFormName!YourComboBoxName substituting the
names of your form and combobox. Then in the combobox
create an OnChange event procedure that requeries the
data.

Forms!YourMainFormName.form!YourSubFormName.Requer
 
J

John

I found out what the problem was. I can't believe it either! I had a different name for the subform. When I renamed the subform I did it in the wrong place

Thank you Tina and John for your help

John
 
V

Van T. Dinh

Try:

Me.SubFormCONTROLName.Form.Requery

Note: SubformCONTROLName may be different from the name
of the Form being used as the Subform (more accurately,
being used as the SourceObject of the SubformControl).
You need to check the SubformControlName in the DesignView
of the (main) Form.

Use AfterUpdate Event.

HTH
Van T. Dinh
MVP (Access)


-----Original Message-----
John,

I tried that and it still didn't work. Here is what I
had in the code for the combo box:
Private Sub cboMonth_AfterUpdate()
Forms!Test_Monthly_Summary.Form! sbfrmQuery_All_Money.Requery
End Sub

I also tried it as cboMonth_Change() like you mentioned and it still didn't work.

In my query I have an expression that normally prompts
the user for the month. Expr1: Month(trans_date) In the
criteria I have the following: [Forms]!
[Test_Monthly_Summary]![cboMonth] This is where the combo
box passes the month to the query for the subform.
 

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

Top