J
Jonathan Stratford
Hi,
I'm a complete novice, but I'm trying to use SQL in a
macro, to send an email from Access. The SQL statement I
use works fine in a query, but doesn't in my code. The
SQL statement, as far as I know, looks in the TEmployees
table for the EmployeeID entered in the corresponding box
and returns the EmployeeName from that row in the table.
in the macro, it complains that there is a syntax error
in the FROM clause, and I don't know why.
The code I use is as follows:
Set con = Application.CurrentProject.Connection
stSql = "SELECT [Employee Name] FROM [TEmployees] WHERE [EmployeeID]=" & Me![EmployeeID]
Set rs = CreateObject("ADODB.Recordset")
rs.Open stSql, con, , , adCmdTable
With the WHERE clause removed the same error occurs,
unsurprisingly.
Can anyone tell me why this code does not work?
Many thanks,
Jonathan Stratford
I'm a complete novice, but I'm trying to use SQL in a
macro, to send an email from Access. The SQL statement I
use works fine in a query, but doesn't in my code. The
SQL statement, as far as I know, looks in the TEmployees
table for the EmployeeID entered in the corresponding box
and returns the EmployeeName from that row in the table.
in the macro, it complains that there is a syntax error
in the FROM clause, and I don't know why.
The code I use is as follows:
Set con = Application.CurrentProject.Connection
stSql = "SELECT [Employee Name] FROM [TEmployees] WHERE [EmployeeID]=" & Me![EmployeeID]
Set rs = CreateObject("ADODB.Recordset")
rs.Open stSql, con, , , adCmdTable
With the WHERE clause removed the same error occurs,
unsurprisingly.
Can anyone tell me why this code does not work?
Many thanks,
Jonathan Stratford