Microsoft Office Tutorials and References
In Depth Information
E-mailing a Selection
Else¶
' skip processing¶
GoTo exit_btnEmail_Click¶
End If¶
End If¶
' Create a recordset for sequential processing¶
Set rs = CurrentDb.OpenRecordset(select * from tblName & strWhere)¶
' Test if the recordset contains records¶
If rs.EOF And rs.BOF Then¶
' No records found¶
MsgBox Your selection gave no rows, please try again¶
GoTo exit_btnEmail_Click¶
End If¶
' position on the first row¶
rs.MoveFirst¶
' loop through all rows till the end of file¶
While Not rs.EOF¶
' send an email for the selected person and allow editing when¶
' the chkEmail has been set to true¶
DoCmd.SendObject acSendNoObject, , , rs!Email, , , Multi mail test,
Dear & rs!LastName & , & vbCrLf & This is a test, Me.chkEmail¶
' read the next record¶
rs.MoveNext¶
Wend¶
exit_btnEmail_Click:¶
End Sub¶
That may seem like a lot of code, but there is just one line still needed for
sending the e-mail – this one:
DoCmd.SendObject acSendNoObject, , , rs!Email, , , Multi mail test,
“Dear “ & rs!LastName & , & vbCrLf & “This is a test”, Me.chkEmail¶
Acs
There are many parameters available. To study them, use the F1 help key. The
first, acSendNoObject, looks a bit odd, but implies that an object like a report is
not going to be mailed. Access attaches it to the e-mail automatically. The
rs!Email takes the e-mail address from the active row and place that in the To
field. The Subject field is filled with a string, and so is the Message Text. The
Message text shows how to use concatenation of strings to personalize the e-
mail by inserting the LastName from the table. It shows how to create multiple
lines by using the vbCRLF system variable.
The code basically consists of two sections: the verification and construction of
the WHERE clause, and the processing of the records selected.
In the first section, the build string is used to create the WHERE string. Access
invisibly adds the qualification string sfrmName. The REPLACE function
Search JabSto ::




Custom Search