How to open a query based on option selected on a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jolaunt
    New Member
    • Apr 2010
    • 16

    #1

    How to open a query based on option selected on a form

    Hi

    I have a form with a drop down field showing different 'series groups' eg

    Series - 75
    Series - 756
    Series - 310

    I have a button to run a query and want a different query to run dependant upon which series group is selected.

    My drop down box is titled "product".

    I have tried the following code which comes back with an error:

    Code:
     Private Sub Command7_Click()
    If Me.Product = "Series - 75" Then
    Me.Query = "GROWTH PRODUCT - 75"
    End If
    End Sub
    I'm sure it's a fairly easy answer but I have been looked at this for about an hour and can't manage to get it working.

    Hope you can help - Thanks in advance.

    Jo
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    I'm afraid this isn't very clear Jo. What do you mean when you say you want to run a query?

    BTW the problem in your code is related to line #3. The .Query property of a form should be set to some sort of code that exececutes when the Query event is fired.

    Comment

    • jolaunt
      New Member
      • Apr 2010
      • 16

      #3
      Sorry I wasn't clear enough.

      I want the query "GROWTH PRODUCT - 75" or relevant query in relation to drop down selection, to open in datasheet view when the button is pressed.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        You'll probably want something like the following then :
        Code:
        Private Sub Command7_Click()
            Select Case Me.Product
            Case "Series - 75"
                Call DoCmd.OpenQuery("GROWTH PRODUCT - 75", acViewNormal)
            Case "Series - 310"
                Call DoCmd.OpenQuery("GROWTH PRODUCT - 310", acViewNormal)
            Case "Series - 756"
                Call DoCmd.OpenQuery("GROWTH PRODUCT - 756", acViewNormal)
            End Select
        End Sub

        Comment

        Working...