Reputation: 111
I'm using an MS access query in which I want to pull all the emails from the query and then populate an outlook email with all the emails, the code will run but, it does not pull in the email addresses and i cannot seem to figure out why.. here is what i have so far. My thoughts are than the query used in populating the table is not being called when trying to pull the emails
Private Sub Command30_Click()
On Error GoTo Err_Command30_Click
Dim stDocName As String
stDocName = "Department E-Mail"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Dim r As Recordset
Dim Email As String
Set r = CurrentDb.OpenRecordset("SELECT[tbl dmgrphcs].Email FROM [tbl dmgrphcs]WHERE(([tbl dmgrphcs].Email) Is Not Null);")
Do While Not r.EOF
Email = Email & r(0) & ";"
r.MoveNext
Loop
r.Close
DoCmd.SendObject acSendNoObject, Null, Null, "", "", Email, "", "", True, Null
Exit_Command30_Click:
Exit Sub
Err_Command30_Click:
MsgBox Err.Description
Resume Exit_Command30_Click
End Sub
Upvotes: 0
Views: 1080
Reputation: 112712
Your use of the table name is not consistent
[tbl dmgrphcs]
[tbl dmgrphcs]
[tbl dmgrphcs]
The number of spaces matters. If the query accesses only one table you don't need to prefix the columns with the table name
Set r = CurrentDb.OpenRecordset("SELECT Email FROM [tbl dmgrphcs] " & _
"WHERE Email Is Not Null")
Hint: Give your buttons meaningful names before adding event handlers. Command30
does not speak. btnPullEMails
or cmdPullEMail
does. The event handler will then have a better name too:
Private Sub btnPullEMails_Click()
Upvotes: 2