Below is a simple example of using the SendObject command, fired by the
OnClick event of a form control called "Email":
==============================
Private Sub email_Click()
If IsNull() Then
MsgBox " No address found ! ", vbExclamation, "Missing e-mail"
Else
On Error Resume Next
DoCmd.SendObject , , , Me![Email], , , "From [your name here]"
End If
If Err.Number = 2501 Then
MsgBox " Email message cancelled ", vbExclamation
End If
Exit_Email_Click:
Exit Sub
Err_Email_Click:
MsgBox Error$
Resume Exit_Email_Click
End Sub
====================================
Here's an example of using a form with a multi-select list box (called
"lstMailTo") and a command button (called "cmdEmail"): Apologies to the
original author whose info I've lost. You'll also need form controls for
the subject line and message text, and you'll need to create the query data
source for the listbox.
==================================
Private Sub cmdEmail_Click()
On Error GoTo Err_cmdEmail_Click
Dim strEmail As String
Dim strMailSubject As String
Dim strMsg As String
strEmail = Me.txtSelected & vbNullString
strMailSubject = Me.txtMailSubject & vbNullString
strMsg = Me.txtMsg & vbNullString & vbCrLf & vbCrLf & "[your signature
here]"
DoCmd.SendObject , , , To:=strEmail, Bcc:=strEmail,
subject:=strMailSubject, MessageText:=strMsg
Err_cmdEmail_Click:
If Err.Number = 2501 Then
MsgBox " Email message cancelled ", vbExclamation
Else
' MsgBox Err.Description
Resume Exit_cmdEmail_Click
End If
Exit_cmdEmail_Click:
Exit Sub
End Sub
Private Sub Form_Open(Cancel As Integer)
Me!lstMailTo.RowSource = "[My Query]"
Me!txtMsg.SetFocus
End Sub
Private Sub lstMailTo_Click()
Dim varItem As Variant
Dim strList As String
Me.cmdEmail.Enabled = True
With Me!lstMailTo
If .MultiSelect = 0 Then
Me!txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ";"
Next varItem
strList = Left$(strList, Len(strList) - 1)
Me!txtSelected = strList
Me!txtTotalSelected.Requery
End If
End With
End Sub
====================================
I typically add unbound controls with expressions to show the # of total
records in the listbox
(=IIf([lstMailto].[ListCount]>0,[lstMailto].[ListCount]-1,0)) and the # of
records selected (=[lstMailto].[itemsSelected].[Count])
Good luck
-Ed