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

show query in subform based on option group

Status
Not open for further replies.

Delindan

MIS
May 27, 2011
203
US
Hi,

I've been attempting to piece this together based on other posts I've seen and still having a problem. Probably obvious but here's what I have. I have a form with an option group at the top named FrameMissing. Based on the option selected, I would like the subform windown below to show a list of records in a premade query. The subform window is called Qmissing. I've never made a form like this before so I am unsure of how to link the subform to the option group selection. The code I came up with based on examples I found is:

Private Sub FrameMissing_AfterUpdate()

Dim qryName As String

Select Case FrameMissing

Case 1
qryName = "BudgetedCC"
Case 2
qryName = "BudgetedSal"
Case 3
qryName = "BudgetedStart"
Case 4
qryName = "ActualCC"
Case 5
qryName = "ActualSal"
Case 6
qryName = "ActualStart"
Case 7
qryName = "ForeStart"
Case 8
qryName = "ForeSal"

End Select

Me.QMissing.Form.RecordSource = qryName

End Sub

Anyone have ideas of what I missed?

Thanks!
 
Anyone have ideas of what I missed
What is the problem ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry forgot to add this. The error I get when I choose a selection is run time error 2467. Object referred to is closed or doesn't exist.

Thanks
 
What is the name of the control hosting the QMissing form ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Is this in the properties of the subform? I've been suspecting I was missing the source object which is blank right now.
 
the source object which is blank right now
Well, you've confused me.
How do you expect to work with a subform that don't have any SourceObject ???
 
Yeah, I know that's the problem...I'm not sure what to put in there because the record source will be different depending on what selection is made from the option group.
 
I was thinking the line Me.QMissing.Form.RecordSource = qryName gives that subform the source object. Apparently this is incorrect since that is where the code is stopping.
 
I got an answer about this from someone and just in case anyone is interested...defining the source object in the vba makes it so you don't have to define in the properties and can vary it depending on the user choice in the option group. In this type of form you use objectsource rather than recordsource and adding query. in front of the query name seemed to get it working.

Private Sub FrameMissing_AfterUpdate()

Dim qryName As String

Select Case FrameMissing

Case 1
qryName = "Query.BudgetedCC"
Case 2
qryName = "Query.BudgetedSal"
Case 3
qryName = "Query.BudgetedStart"
Case 4
qryName = "Query.ActualCC"
Case 5
qryName = "Query.ActualSal"
Case 6
qryName = "Query.ActualStart"
Case 7
qryName = "Query.ForeStart"
Case 8
qryName = "Query.ForeSal"

End Select

Me.QMissing.SourceObject = qryName

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top