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

Execute Query for inside VBA Code

Status
Not open for further replies.

kkitt

Programmer
Dec 1, 2002
122
US
I am trying to run a specific query that is pre-defined as a stand-alone query inside of my VBA Code using the "RUNSQL" command as below:

Code:
       DoCmd.RunSQL "#GetFirstCustomerCall", 0

the query contains:

Code:
   UPDATE tblCDNCustData SET tblCDNCustData.tblFCareRepName = funReturnUser()
WHERE (((tblCDNCustData.[Ship To Phone Num])=(Select top 1 [Ship To Phone Num] from tblCDNCustData where tblFCareRepName is null and tblFCustCalled = false and tblEstDeliveryDate is not null)));

The Error Message that I am getting is:

Code:
   "Invalid SQL Statement; expected 'Delete', 'Insert', Procedure','Select', or 'Update'

I also get the same Error message if I try to perform this as a Macro...

When I go the the query screen and double click on the query it runs with no issues and performs the updates... What am i doing wrong???

Thanks in advance
 
dim sqltxt as string

sqltxt = "UPDATE tblCDNCustData SET tblCDNCustData.tblFCareRepName = funReturnUser()
WHERE (((tblCDNCustData.[Ship To Phone Num])=(Select top 1 [Ship To Phone Num] from tblCDNCustData where tblFCareRepName is null and tblFCustCalled = false and tblEstDeliveryDate is not null)))"

docmd.runsql sqltxt

or

docmd.openquery "YourQueryName
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top