我正在尝试在VBA宏中运行此SQL语句,但出于某种原因,由于我无法查明的语法错误,它不会运行。我对VBA很陌生,所以任何帮助确定这个错误的人都会非常感激。
Dim dte As String, db As Database, tableName As String, DataDump As Recordset, clientTable As Recordset
Set db = CurrentDb
dte = InputBox("What date was the Data Dump run?", "Please Input a date")
tableName = "FN_DataDump_ALL_" & dte
Set DataDump = db.OpenRecordset(tableName, dbOpenDynaset, dbEditAdd)
Set clientTable = db.OpenRecordset("Clients", dbOpenDynaset, dbEditAdd)
MySQL = "SELECT DISTINCT DD.[Client ID] " & _
"INTO Clients " & _
"FROM " & tableName & "as DD " & _
"Where CL.[Client ID] NOT IN (SELECT DD.[Client ID] ""FROM"" & tableName & ""as DD"") "
db.Execute MySQL
答案 0 :(得分:2)
FROM
周围的引号错误,而TABLENAMEAS
生成了缺失的空格,而是:
= "SELECT DISTINCT DD.[Client ID] " & _
"INTO Clients " & _
"FROM " & tableName & " as DD " & _
"Where CL.[Client ID] NOT IN (SELECT DD.[Client ID] FROM " & tableName & " as DD)"