By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,973 Members | 1,535 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,973 IT Pros & Developers. It's quick & easy.

Skip blank email addresses when sending email from Outlook thru Access

P: 9
This site is fantastic, first of all. Second of all, thank you for your time in this matter.

I have been using some code that was posted on here (I apologize for not being able to remember who) to send out emails from Outlook through Access. This has been working great until recently. When there is no entry in the email address field of my queries, the code crashes. How can I circumvent this error, without having to fill in the email address field?

Here is the code that I have been using:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSendEmail_Click()
  2. Dim rcdst As DAO.Recordset
  3. Dim strRecipients As String
  4. Dim strSubject As String
  5. Dim strBody As String
  7. strSubject = txtSubject
  8. strBody = txtMsgBody
  10. Set rcdst = CurrentDb.OpenRecordset(txtQryName, dbOpenForwardOnly)
  11. While Not rcdst.EOF
  12.         strRecipients = strRecipients & rcdst(txtEmailFieldName) & ";"
  13.         rcdst.MoveNext
  14. Wend
  15. DoCmd.SendObject acSendNoObject, , , , , strRecipients, strSubject, strBody & vbCr
  16. rcdst.Close
  17. Set rcdst = Nothing
  19. End Sub
Aug 23 '07 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 10K+
P: 12,408
Have the query not return e-mail address that are null.
Aug 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.