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

    Build Query from cmdButton

    I've been struggling with this for 2 days and cannot get it to work. I have two combo boxes that I want to use to filter qSourceData_Test. I can get the query to open with the correct fields but there is no data. i know it's something simple and would appreciate another set of eyes.

    Private Sub btnRunQuery_Click()
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim strSQL As String
    Set db = CurrentDb
    Set qdf = db.QueryDefs("qryBuildQuery")

    strSQL = "SELECT qSourceData_Test.* " & _
    "FROM qSourceData_Test " & _
    "WHERE qSourceData_Test.SOURCING_SEASON='" & Me.cboSeason.Value & "' " & _
    "AND qSourceData_Test.SAP_CAT_DESC='" & Me.cboCategory.Value & "' " & _
    "ORDER BY qSourceData_Test.DEV_CD;"

    qdf.SQL = strSQL
    DoCmd.OpenQuery "qryBuildQuery"


    DoCmd.Close acForm, Me.Name

    Set qdfTemp = Nothing
    Set db = Nothing

    Thank you!

  2. #2
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    Another way of doing this is just filter in the actual query. In the query on the field for cboCategory put something like this in the criteria: Forms!FormName!cboCategory

    JNow you just need to replace 'FormName' with the name of the form that cboCategory is on and test your query.

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

Similar Threads

  1. Hellp with Query Build
    By zarfx4 in forum Queries
    Replies: 0
    Last Post: 05-28-2009, 08:21 AM
  2. Replies: 0
    Last Post: 01-18-2009, 09:18 PM
  3. Build a book with records
    By phoobie in forum Reports
    Replies: 0
    Last Post: 09-06-2008, 10:56 AM
  4. Can access build a exe file?
    By jianwei87 in forum Programming
    Replies: 1
    Last Post: 08-04-2008, 06:48 AM

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