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

doCMD.RunSQL Problem

Status
Not open for further replies.
Joined
Nov 16, 2006
Messages
19
Location
GB
I run the following from a command button:

Code:
   Dim strSQL As String
    
    strSQL = "SELECT tbl_Agents.[AgentName], tbl_Agents.[Aspect_No] " & _
            "FROM tbl_Agents " & _
            "WHERE tbl_Agents.[TM_ID] = " & Form_frm_TMs.dd_TMID.Value & ";"

    DoCmd.RunSQL (strSQL)

And get an error of "A runSQL action requires an argument consisting of an SQL statement."

When i use the immediate window to get the string and place it into the sql query window and run it it works fine.

Code:
?strSQL
SELECT tbl_Agents.[AgentName], tbl_Agents.[Aspect_No] FROM tbl_Agents WHERE tbl_Agents.[TM_ID] = '2';

what am i doing wrong?
 
Code:
SELECT tbl_Agents.[AgentName], tbl_Agents.[Aspect_No] FROM tbl_Agents WHERE tbl_Agents.[TM_ID] = 2;

Sorry, that's how it appears in the immediate window
 

Right from help file
DoCmd.RunSQL needs a valid SQL statement for an action query or a data-definition query.

You are running a select SQL statement
 
Have a look at the DLookUp function.

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