Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2002

    Unanswered: Parameter Query in VBA code

    I have a form that i want to run a query when i leave a text box. The query is a parameter query and when i run it normally it is fine yet when i open it in code i get an error message saying that it is expecting 1 parameter.
    Has anyone any ideas on how to get around this.


  2. #2
    Join Date
    Feb 2002
    Dublin, OH
    There are a couple of ways to do this. If the query will be run only from a single form, you can explicitly refer to the field on the form in your parameter:

    Instead of entering the following in the criteria: > [Start Date]

    enter: > Forms![frmOrders]![txtStartDate]

    If the query will be executed by different forms, you can put the query in the code for the form. If it is a select query, you will have to dump the data to table and then open that table. If it is an action query, you can just execute it.

    For example, to pull all information from a table called Orders based on the order status, you could put the following in the AfterUpdate event for the text box:

    Private Sub txtOrderStatus_AfterUpdate()

    'Turn off warnings
    DoCmd.setwarnings False

    'Dump output of query into temporary table
    DoCmd.RunSQL "SELECT * INTO tblTemp FROM OrdersWHERE OrdStat=""" & txtOrderStatus& """;"

    'open temporary table
    DoCmd.OpenTable "tblTemp"

    'turn warnings back on
    DoCmd.setwarnings True

    End Sub
    Last edited by rottpaws; 02-21-02 at 16:09.
    Patrick Mildenberg

Posting Permissions

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