Setting query parameters through VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tomric
    New Member
    • Nov 2009
    • 31

    Setting query parameters through VBA

    I have a query that looks at two forms. The first form provides a number to pull a group of records out of a table. The second from provides a series of 8 different check boxes that the query ueses to filter the data as required by the person using it. The query works great when looking at the table or a report. Im having problems when I open the query in code to send it to excell for graphing. I don't know how to get the query to look at the parameters and pass the correct data. Right now I can get it to look at one parameter Using a For loop:
    Code:
     Set dbs = CurrentDb
       Set qdf = dbs.QueryDefs!Noncatalogpartsbybarnumber
       For Each prm In qdf.Parameters
            prm.Value = parameter
        Next prm
    The loop will run through 8 times for each parameter, but it only sees the number from the first form. How do I get it to look at the the the check box values, -1 or 0, and set the parameter for the query.

    Thank you for any help you can give.
    Last edited by NeoPa; Jan 8 '11, 03:20 PM. Reason: Please use the CODE tags provided
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Try:
    Code:
    Dim dbs As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim prm As DAO.Parameter
    
    Set dbs = CurrentDb
    Set qdf = dbs.QueryDefs!Noncatalogpartsbybarnumber
    
    For Each prm In qdf.Parameters
      prm.Value = Eval(prm.Name)
    Next prm
    P.S. - Both Forms must be 'Open'

    Comment

    • tomric
      New Member
      • Nov 2009
      • 31

      #3
      Thank you. Both forms are open, but how do I change the parameter name in the evaluation statement, Eval(prm.Name)? All the parameter will have different names

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        You don't change the Names, since the Parameters represent the actual Criteria, such as: Forms!Form1!chk Something=True.

        Comment

        • tomric
          New Member
          • Nov 2009
          • 31

          #5
          Thaank you very much. It's working just fine.

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Glad it all worked out for you.

            Comment

            Working...