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
- Private Sub cmdSendEmail_Click()
- Dim rcdst As DAO.Recordset
- Dim strRecipients As String
- Dim strSubject As String
- Dim strBody As String
- strSubject = txtSubject
- strBody = txtMsgBody
- Set rcdst = CurrentDb.OpenRecordset(txtQryName, dbOpenForwardOnly)
- While Not rcdst.EOF
- strRecipients = strRecipients & rcdst(txtEmailFieldName) & ";"
- rcdst.MoveNext
- Wend
- DoCmd.SendObject acSendNoObject, , , , , strRecipients, strSubject, strBody & vbCr
- rcdst.Close
- Set rcdst = Nothing
- End Sub