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.
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
'Dump output of query into temporary table
DoCmd.RunSQL "SELECT * INTO tblTemp FROM OrdersWHERE OrdStat=""" & txtOrderStatus& """;"