This is my first post, well, ever...
So here it goes.
I'm writing a chunk of code that finds an email address in a table, then places it into the SendObject method.
When I try to run it I get the dreaded 3011.
Please help.
Ps. I only got this far thanks to people's posts and your responses. So thanks so much for that =)
Here's the code:
Expand|Select|Wrap|Line Numbers
- Dim strTo As String
- Dim rst As dao.Recordset
- Dim dbs As Database
- Dim strSQL As String
- Dim strtablename As String
- strtablename = "Branches"
- Set dbs = CurrentDb()
- strSQL = "SELECT Email_Address AS EmailAddress FROM " & strtablename & " WHERE Branch_Code= " & TempVars("SelectedBranch").Value
- ' The above SQL is all one line, so there's no need to put any underscores
- ' I also tried Branches.[Email Address] and [Email Address]
- Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenTable)
- DoCmd.SendObject acSendQuery, bla bla bla, strTo, , , bla bla bla
the funny thing is, when I use this SQL in a query in access, it works fine. When I put it in the openrecordset in VBA, I get the 3011.
Expand|Select|Wrap|Line Numbers
- (
- SELECT Branches.[Email Address]
- FROM Branches
- WHERE (((Branches.[Branch Code])=112));
- )
Any help would be appreciated.
Much thanks, peace and love