SQL statement doesn't work in VBA.

D

Dan

When I run the following, it gave me " A RunSQL action requires an argument
consisting of an SQL statement". Can anyone help?

Dim SQL as String
SQL = "SELECT [Contact List].[RFQ Vendor], [Contact List].[Email Sent],
[Contact List].Email, [Contact List].SupplierCCEmail, RFQ_Master.* " & _
"FROM RFQ_Master INNER JOIN [Contact List] ON RFQ_Master.[RFQ Vendor] =
[Contact List].[RFQ Vendor];"
DoCmd.RunSQL SQL
 
P

Paolo

Hi Dan,
I'm pretty sure SQL is an access reserved word. Change the name of your
variable. e.g.

Dim str_SQL as String
str_SQL = "SELECT [Contact List].[RFQ Vendor], [Contact List].[Email Sent],
[Contact List].Email, [Contact List].SupplierCCEmail, RFQ_Master.* " & _
"FROM RFQ_Master INNER JOIN [Contact List] ON RFQ_Master.[RFQ Vendor] =
[Contact List].[RFQ Vendor];"
DoCmd.RunSQL (str_SQL)

HTH Paolo
 
P

Paolo

I didn't notice that the statement was just a select query. As Chris said
runsql requires an action query or a data definition query

Paolo said:
Hi Dan,
I'm pretty sure SQL is an access reserved word. Change the name of your
variable. e.g.

Dim str_SQL as String
str_SQL = "SELECT [Contact List].[RFQ Vendor], [Contact List].[Email Sent],
[Contact List].Email, [Contact List].SupplierCCEmail, RFQ_Master.* " & _
"FROM RFQ_Master INNER JOIN [Contact List] ON RFQ_Master.[RFQ Vendor] =
[Contact List].[RFQ Vendor];"
DoCmd.RunSQL (str_SQL)

HTH Paolo

Dan said:
When I run the following, it gave me " A RunSQL action requires an argument
consisting of an SQL statement". Can anyone help?

Dim SQL as String
SQL = "SELECT [Contact List].[RFQ Vendor], [Contact List].[Email Sent],
[Contact List].Email, [Contact List].SupplierCCEmail, RFQ_Master.* " & _
"FROM RFQ_Master INNER JOIN [Contact List] ON RFQ_Master.[RFQ Vendor] =
[Contact List].[RFQ Vendor];"
DoCmd.RunSQL SQL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SQL -- VBA 3
SQL Query in VBA 9
Using Date fields in SQL 2
SQL - VBA once again 10
VBA query trouble 3
Open select query in vba code 4
Running a SELECT statement 2
Stop Query 4

Top