Run a Specific Query based on ComboBox Value

aldeb

Registered User.
Local time
Yesterday, 21:15
Joined
Dec 23, 2004
Messages
318
Below is the code that I have on a comboBox AfterUpdate
Event. It runs a query and uses the value of Distinct
Behavior for the criteria. The Distinct Behaviors dropdown
is based on what is slected from a Dropdown from a Distinct
Categories ComboBox. What I would like is to run a specific
Query based on what is selected from the Distinct Behaviors
ComboBox. Any advice?

Code:
Private Sub DistinctCategories_AfterUpdate()
   On Error Resume Next
   DistinctBehaviors.RowSource = "SELECT DISTINCT ObserversSecondTbl.Behaviors " & _
            "FROM ObserversSecondTbl " & _
            "WHERE ObserversSecondTbl.Categories = '" & DistinctCategories.Value & "' " & _
            "ORDER BY ObserversSecondTbl.Behaviors;"
 
you haven't said what's happening (or not).
you might need to requery the combo box after changing the row source?
 
Currenly when I select the drowpdown from DistinctCategories
it populates DistinctBehaviors Dropdown. When I select the
Value in the DistinctBehaviors dropdown it runs a query
using the DistinctBehaviors Value as the criteria for a
Query. I would like to run a different query for each value
in the DistinctBehaviors Dropdown. Hope this explains myself
a little better. Sorry for the confusion and thanks for the
help!

I would rather have a different query for each value
in the Distinct Behaviors Dropdown to run. The one query
already changes the criteria based on this dropdown but
I need to select different fields for each value of the
dropdown and not just the criteria.

Code:
Private Sub DistinctBehaviors_AfterUpdate()

DoCmd.OpenQuery "CategoriesBehaviorsMainQry"
Me.DistinctCategories = Clear
Me.DistinctBehaviors = Clear

End Sub
Code:
Private Sub DistinctCategories_AfterUpdate()

   On Error Resume Next
   DistinctBehaviors.RowSource = "SELECT DISTINCT ObserversSecondTbl.Behaviors " & _
            "FROM ObserversSecondTbl " & _
            "WHERE ObserversSecondTbl.Categories = '" & DistinctCategories.Value & "' " & _
            "ORDER BY ObserversSecondTbl.Behaviors;"
            
'   Me.DistinctCategories = Blank
 '  Me.DistinctBehaviors = Blank
            
'   On Error Resume Next
'   SystemGroup.RowSource = "SELECT DISTINCT TroubleShootingGuideTBL.SystemGroup " & _
'            "FROM TroubleShootingGuideTBL " & _
'            "WHERE TroubleShootingGuideTBL.FaultCategory = '" & FaultCategory.Value & "' " & _
'            "ORDER BY TroubleShootingGuideTBL.SystemGroup;"
 
I went this way and it works. Thanks everyone


Code:
Private Sub DistinctBehaviors_AfterUpdate()

If Me.DistinctBehaviors = "Eye Protection" Then
DoCmd.OpenQuery "DistinctBehaviorsPPEEyeProQry"
End If
 

Users who are viewing this thread

Back
Top Bottom