Hi, I'm having issues trying to get the following simple SELECT to run as part of a word mail merge using vba .
I've tried a few variations on the SQL each with different syntax related errors eg:
etc including with and without a trailing semicolon.
The error that from the first SQL statement (in the main code block) is:
I'm well versed in T-SQL but not Access's SQL syntax, however all of these seem to work when executed from Access.
I have also tried a few variations on the vba code, such as excluding a
Any help is appreciated. The solution is probably blinding obvious, but I can't see it.
Code:
UserName = (Environ$("Username"))
sDBPath = "U:\" & UserName & "\db.accdb"
SQL = "SELECT * FROM [TestName] T INNER JOIN [TestNameData] D ON T.TestNameId = D.TestNameId"
Connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sDBPath & ";"
DefaultName = ActiveDocument.Name
Fname = ActiveDocument.BuiltInDocumentProperties("Title")
With ActiveDocument.MailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource Name:=sDBPath, _
LinkToSource:=True, _
Connection:=Connection, _
SQLStatement:=SQL
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
'[ Rest of code Snipped]
I've tried a few variations on the SQL each with different syntax related errors eg:
"SELECT * FROM [TestName] T INNER JOIN [TestNameData] D ON (T.TestNameId = D.TestNameId)"
"SELECT * FROM ([TestName] T INNER JOIN [TestNameData] D ON (T.TestNameId = D.TestNameId))"
etc including with and without a trailing semicolon.
The error that from the first SQL statement (in the main code block) is:
I'm well versed in T-SQL but not Access's SQL syntax, however all of these seem to work when executed from Access.
I have also tried a few variations on the vba code, such as excluding a
Connection
argument.Any help is appreciated. The solution is probably blinding obvious, but I can't see it.