Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2002

    Unanswered: Using DoCmd.OpenQuery with query parameters

    I need to open a query when a person clicks a button on a form. This query requires a couple of parameters which will be entered into the text boxes on the form.

    How do I include the parameters as part of the query?

    I was thinking along the lines of:

    DoCmd.OpenQuery( "SELECT * FROM Table WHERE Param1 = 'text'" )

    Any suggestions as to how this can be done?


  2. #2
    Join Date
    Mar 2002
    Instead of using the DoCmd.OpenQuery command, use the DoCmdRunSQL. You can insert the values into the select statement. The Open Query only allows you to run the a predefined query.

    Example: Docmd.RunSql ("Select *** from table ** where ***= '" & txtboxvalue "' and so on.

    Let me know if this helps.


  3. #3
    Join Date
    Feb 2002
    North Carolina

    If the form is going to be open when you are running the query, you can set the parameters to controls on the form. For example, assume you have a textbox called Textbox1 on your form that will contain the value you need for the query. Open your query in design mode. On the Criteria line for the field in the query that needs to get its value from the form, enter the following (change the form name and control name as appropriate):


    As long as the form is open when the query is called, the query can reference the value of a control on the form in this manner.

    Hope it helps--

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts