I've been trying the same thing and finally got it to work - with a lot of
help from the community members here.
My database is used for project management. Each project can be assigned
several resources, each of which is assigned to a functional area. Members
who are in more than one functional area are entered multiple times. All the
entry takes place in a form. Said form has a combo box to select the
functional group to send the email to. This value gets appended with "*" so
that if it is blank it will send the email to everyone.
Following is the code I have so far. I checked a sample and found that the
string length works up to at least 450 characters. Feel free to use/modify
it if it works for you.
Private Sub btnEmailFunction_Click()
On Error GoTo btnEmailFunction_Err
Dim rst As DAO.Recordset
Dim db As DAO.database
Dim strEmail As String
Dim strQuery As String
strQuery = _
"SELECT tblEmployees.EmailAddress " & _
"FROM (tblEmployees INNER JOIN tblProjectSupport ON " & _
"tblEmployees.[Employee ID] = tblProjectSupport.EmployeeID) " & _
"INNER JOIN tblDefFunction ON tblProjectSupport.FunctionID " & _
"= tblDefFunction.FunctionID " & _
"WHERE (((tblProjectSupport.ProjectID) = " & _
[Forms]![frmProjectSupport].[FilterProjectID] & _
") And ((tblDefFunction.FunctionDesc) Like " & Chr(34) & _
[Forms]![frmProjectSupport].[EmailFunctionDesc] & "*" & Chr(34) & _
")) GROUP BY tblEmployees.EmailAddress " & _
"HAVING (((tblEmployees.EMailAddress) Is Not Null)) " & _
"ORDER BY tblEmployees.EmailAddress;"
Set db = CurrentDb()
Set rst = db.OpenRecordset(strQuery)
With rst
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
strEmail = .Fields("EmailAddress")
.MoveNext
End If
If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
strEmail = strEmail & "; " & .Fields("EmailAddress")
.MoveNext
Loop
End If
.Close
End With
If strEmail = "" Then
MsgBox "No email addresses were found. " & _
"Please check the employee records and try again."
Else:
DoCmd.SendObject acSendNoObject, , acFormatTXT, strEmail, _
, , "Subject", "Message goes here", True
End If
btnEmailFunction_Exit:
Exit Sub
btnEmailFunction_Err:
Select Case Err.Number
Case 2501 'user canceled email
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in event"
End Select
Resume btnEmailFunction_Exit
End Sub
Connie said:
Hi Steven
Thank you very much. I'm pretty much ok with setting up a macro to email
and attach a snapshot. But say I want to give more control to the user, ie:
they select the report to attach and they select the recipients to send it to.
Having said that, there may be 100 or more recipients for a particular
report. So setting up a group in the first place is much cleaner. Then
users can simply select the group and report(s), then click 'send'. My
quesiton is, is there a way I can do this? Any ideas?
Connie