SQL statement doesn't work in VBA.

  • Thread starter Thread starter Dan
  • Start date Start date
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
 
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
 
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
 
Back
Top