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 Optiongroup Changes Mainform Recordsource

Status
Not open for further replies.

ThomasLafferty

Instructor
Mar 14, 2005
549
US
Hi!
I have an option group named QueryDriverGroup on a subform embedded in a main form named Drivers, and I want to use it to apply one of three queries as a recordsource for my main form.

I looked over faq181-447 concerning subform syntax and wasn't able to find a line that would work.

My thought was:
Code:
Private Sub QueryDriverGroup_AfterUpdate()
'apply a different data source according to user choice

    On Error GoTo Err_QueryDriverGroup_AfterUpdate
    
    Select Case Me.QueryDriverGroup.Value
        Case Me.QueryDriverGroup.Value = 1      'default: Heavy Haul
            Me.Parent.RecordSource = "qryDriverGroup_HeavyHaul"
            
        Case Me.QueryDriverGroup.Value = 2      'local drivers
            Me.Parent.RecordSource = "qryDriverGroup_Local"
            
        Case Me.QueryDriverGroup.Value = 3      'all employees
            Me.Parent.RecordSource = "qryDriverGroup_All"
        Case Else   'shouldn't happen, only 3 values
    End Select
    
    'Apply the user's choice
    Me.Parent.Requery
    
Exit_QueryDriverGroup_AfterUpdate:
    Exit Sub
    
Err_QueryDriverGroup_AfterUpdate:
    MsgBox Err.Description
    Resume Exit_QueryDriverGroup_AfterUpdate
    
End Sub

I do not get an error, but it doesn't apply the datasource either. Ideas?

Thanks!


Live once die twice; live twice die once.
 
Select Case Me.QueryDriverGroup.Value
Case [!]Me.QueryDriverGroup.Value =[/!] 1 'default: Heavy Haul
Me.Parent.RecordSource = "qryDriverGroup_HeavyHaul"

Case [!]Me.QueryDriverGroup.Value =[/!] 2 'local drivers
Me.Parent.RecordSource = "qryDriverGroup_Local"

Case [!]Me.QueryDriverGroup.Value =[/!] 3 'all employees
Me.Parent.RecordSource = "qryDriverGroup_All"
Case Else 'shouldn't happen, only 3 values
End Select

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Cool - I will try it on Monday. By the way, I'm not sure why it should make a difference shortening the case statement. If I remember right, I am already using a similar routine on the subform to apply different record sources to the subform - but I will give it a shot.

Thanks again for your help.


Live once die twice; live twice die once.
 
Hi, Thomas,

This issue has popped up several times lately. Seems re-stating the expression (rather than just the potential value) from the Select statement within the Case statement causes the Select Case to not execute properly.

HTH,

Ken S.
 
Tried it this morning - that was it! Thanks.

Tom

Live once die twice; live twice die once.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top