VBA to execute SQL query

JamesN

Registered User.
Local time
Today, 06:27
Joined
Jul 8, 2016
Messages
78
Hi,

I have an SQL query which updates records in a table based on combo box entries within a form.

I want to assign this SQL query to a button within the form, when this button is clicked I want the SQL query to be executed. Query is called 'DisputeWarehouse Query'.

Tried this code but getting an error mentioning the 'while' and 'until'
- do.cmd.openquery ("DisputeWarehouse Query")

Any support ia appreciated.

Thanks

James
 
Two things.

First, it's DoCmd, not Do.Cmd

Second, the OpenQuery method only works for select queries. What you're looking for is the RunSQL method.
 
Tried the below but getting an error, am i missing something?

DoCmd.RunSQL ("DisputeWarehouse Query")
 
Second, the OpenQuery method only works for select queries. What you're looking for is the RunSQL method.

Not true on both counts I'm afraid.

DoCmd.OpenQuery "Your Query Name" Will run an update query, with warnings that you are about to update x records

DoCmd.RunSql expects to see a SQL Query Statement not a query name.
 

Users who are viewing this thread

Back
Top Bottom