Results 1 to 8 of 8
  1. #1
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83

    Combo box and filter query

    This is driving me crazy, I've done it many times before but no code I use seems to be working for this project.

    I have a Select query and a form with a simple combo box and command button on it. I want users to be able to select the Season they want to run, click the button and have the query run filtering it on the combo box selection.

    What am I missing here? I can now get the query to run but it won't filter the results.


    Private Sub cmdSeason_Click()
    Dim strSQL As String
    Dim strWhere As String
    Dim stDocName As String
    strWhere = "WHERE"
    stDocName = "qSourceData_AllSeasons"

    strWhere = strWhere & "[SELL SEASON] = '" & Me.cboSeason.Value & "'"
    strSQL = "SELECT * " & "stDocName"
    strSQL = "strWhere & strSQL"
    DoCmd.OpenQuery stDocName, , , strSQL
    Debug.Print


    End Sub

    Would appreciate any help. Haven't been able to find any threads addressing this which I find unusual so perhaps I'm searching for the wrong keywords: combo box, filter query, strWhere, strSQL, etc.

    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I'm surprised you're not getting an error; OpenQuery has no such argument. OpenForm and OpenReport do:

    BaldyWeb wherecondition

    By the way, even if it were valid, there are numerous other mistakes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ConneXionLost's Avatar
    ConneXionLost is offline Simulacrum
    Windows XP Access 2003
    Join Date
    Jan 2010
    Location
    Victoria, Canada
    Posts
    291
    Place this:

    Code:
    [Forms]![Your form name here]![cboSeason]
    in the select query as criteria for the field you want to filter.

    Simplify the code for your button so it only opens the query.

    Cheers,

  4. #4
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83
    Thanks for the tips, was making it more complicated than it is.

  5. #5
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83
    Just tried this and am getting no data when selecting a season from my combo box.
    I have the rowsource of the combo box set to tblSeasons.
    Do I need to manipulate the VBA code behind the cmd button for it to read my combo box selection? I've checked my criteria and have Form!frmName!cboSeason in there correctly.

    Thanks

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    What is your code now? What is the bound column of the combo, and is it the value expected by the query?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83
    Bingo! Can't believe I've been out of the Access world for less than 2 years and feel like I'm starting all over again! I had the bound column set incorrectly, it is now working perfectly.

    Thank you!

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No problemo, glad we got it sorted out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Filter by combo box & text box?
    By sparkyboy2406 in forum Forms
    Replies: 2
    Last Post: 02-24-2010, 04:20 PM
  2. Using Cascading Combo Boxes to Filter a Query
    By skiptotheend in forum Queries
    Replies: 0
    Last Post: 10-13-2009, 06:57 AM
  3. filter form based on combo box
    By lloyddobler in forum Forms
    Replies: 8
    Last Post: 09-10-2009, 07:33 AM
  4. Combo Box Filter
    By jgelpi in forum Programming
    Replies: 3
    Last Post: 07-27-2009, 12:54 PM
  5. Applying a filter to a combo box
    By bugchaser in forum Programming
    Replies: 1
    Last Post: 02-20-2009, 02:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums