Passing SQL Query result into variable

Jonny

Registered User.
Local time
Today, 11:31
Joined
Aug 12, 2005
Messages
144
How can I pass the result of strSQL into "Received_By" variable?
Code:
    strSQL = "SELECT Employees.[Employee ID], Employees.[Employee Name] " & _
                "FROM Employees " & _
                "WHERE Employees.[Employee Name] ='" & Received_By & "';"

    objMail.To = Received_By
Thanks in advance
 
You have to first run the query using:
Dim rs as dao.recordset
set rs = currentdb.openrecordset(strSQL)

objMail.To = rs![Employee ID]

BTW: You problably know this, but using spaces in column names is a bad thing
BTW2: Do you have a query Employee? Or form Employee?? It is "good practice" to prefix objects to be able to split them from eachother.... I.e. tblEmployee, qryEmployee, etc.
 
Thank you for your advices.. Now it works!
 
Jonny, as you may appreciate this exact question was posted on a sister site and was answered fully, would be nice if you could let us know.

David
 

Users who are viewing this thread

Back
Top Bottom