Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA and DoCmd.RunSQL not working 1

Status
Not open for further replies.

cs211024

MIS
Aug 14, 2003
28
0
0
CA
Here is my code:
*************
Private Sub VerifyAddress_Click()

Dim strSQL As String

If Forms!MAIN!Country = "USA" Then
strSQL = "SELECT ZIPCODEWORLDBASIC.state FROM ZIPCODEWORLDBASIC;"
ElseIf Forms!MAIN!Country = "CANADA" Then
strSQL = "SELECT * FROM IP;"
Else
MsgBox "Please Input the Country first."
Exit Sub
End If

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True

End Sub
*************

The error message is "A RunSQL action requires an argument consisting of an SQL statement."

I have no clue about since everything seems fine. Thanks for your help.
 
DoCmd.RunSQL is for executing action queries (Append, Update, Delete), not SELECT queries where you simply wish to return data.

What exactly are you attempting to do?
 
I want to open an query. Maybe I should try "execute" command. But I do remember that DoCmd.RunSQL can take an select query as its argument.

 
No, it cannot. If you attempt it, you will get the following error message:

Run-Time Error '2342':
A RunSQL action requires an argument consisting of an SQL statement.


The SQL Statement must be either for an action query (a query that copies or changes data) or a data-definition query (a query that can create, alter or delete a table, or create or delete an index). It can NOT be a SELECT query.


Likewise, the "execute" action has exactly the same stipulation.


Is it your wish to retrieve data from the query you are trying to create? If so, what specific data are you trying to retrieve from what field(s) in what table(s), and where/how are you trying to use the information?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top