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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.RunSQL returns error 2342

Status
Not open for further replies.

Chew407

Technical User
Mar 28, 2005
92
CA
I am trying to run an SQL statement from vb but keep getting the error 2342 - A RunSQL action requires an argument consisting of an SQL statement. I stored the SQL in a variable and tried using DoCmd.RunSQL. The code...
Code:
Dim mySQL As String
mySQL = "Select [LKP_tblRouteCodes].[Route Number]"
mySQL = mySQL + "from LKP_tblRouteCodes where ((([Route Code]) = 'A'))"

If cboRouteCodes = "A" Then

DoCmd.RunSQL mySQL

Any ideas what's wrong? Any help you provide is much appreciated. Thanks.

Chew
 
RunSQL is for action queries, not select queries. You may want to use DoCmd.OpenQuery.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
You may also consider the DLookUp function:
someVariable = DLookUp("[Route Number]", "LKP_tblRouteCodes", "[Route Code]='A'")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top