BarryMK
4 strings are enough
- Local time
- Today, 16:51
- Joined
- Oct 15, 2002
- Messages
- 1,350
I found some code that sends emails to multiple addresses stored in a table in
http://www.access-programmers.co.uk/forums/showthread.php?t=66121&highlight=email+multiple that I've tested and it works.
On adding it to my existing working code (coloured blue) to input fields into the strBody and a subject line in strSubject I get Runtime Error 2467 The expression you entered refers to an object that is closed or doesn't exist.
The code is breaking on the line 'strBody = "You have received a new " & Me!cmbType.Column(1) & " raised by customer " & Me!cmbSal.Column(1) & " " & Me!txtLastName & ". This is Compliments and Complaints database record number " & Me!txtCompID & ". The customer's comments were: " & Me!memComments & ". Please action" '
Private Sub cmdClose_Click()
If MsgBox("Have you selected the record type and filled in the other yellow fields? These are mandatory. If you've missed any - click on 'No' to return to form", vbQuestion + vbYesNo, "Close Form?") = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdClose
DoCmd.SetWarnings True
End If
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strEmail As String
Dim strBody As String
Dim strSubject As String
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
rs.Open "tblPlannersEmails", cn
With rs
Do While Not .EOF
strEmail = strEmail & .Fields("Mailadd") & ";"
.MoveNext
Loop
.Close
End With
strSubject = "New feedback from a customer at SomewhereBranch"
strBody = "You have received a new " & Me!cmbType.Column(1) & " raised by customer " & Me!cmbSal.Column(1) & " " & Me!txtLastName & ". This is Compliments and Complaints database record number " & Me!txtCompID & ". The customer's comments were: " & Me!memComments & ". Please action"
DoCmd.RunCommand acCmdSaveRecord
strEmail = Left(strEmail, Len(strEmail) - 1)
DoCmd.SendObject , , , strEmail, , , strSubject, strBody, True
DoCmd.OpenForm "frmSwitchboard"
DoCmd.Close acForm, "frmSelectNew"
End Sub
http://www.access-programmers.co.uk/forums/showthread.php?t=66121&highlight=email+multiple that I've tested and it works.
On adding it to my existing working code (coloured blue) to input fields into the strBody and a subject line in strSubject I get Runtime Error 2467 The expression you entered refers to an object that is closed or doesn't exist.
The code is breaking on the line 'strBody = "You have received a new " & Me!cmbType.Column(1) & " raised by customer " & Me!cmbSal.Column(1) & " " & Me!txtLastName & ". This is Compliments and Complaints database record number " & Me!txtCompID & ". The customer's comments were: " & Me!memComments & ". Please action" '
Private Sub cmdClose_Click()
If MsgBox("Have you selected the record type and filled in the other yellow fields? These are mandatory. If you've missed any - click on 'No' to return to form", vbQuestion + vbYesNo, "Close Form?") = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdClose
DoCmd.SetWarnings True
End If
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strEmail As String
Dim strBody As String
Dim strSubject As String
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
rs.Open "tblPlannersEmails", cn
With rs
Do While Not .EOF
strEmail = strEmail & .Fields("Mailadd") & ";"
.MoveNext
Loop
.Close
End With
strSubject = "New feedback from a customer at SomewhereBranch"
strBody = "You have received a new " & Me!cmbType.Column(1) & " raised by customer " & Me!cmbSal.Column(1) & " " & Me!txtLastName & ". This is Compliments and Complaints database record number " & Me!txtCompID & ". The customer's comments were: " & Me!memComments & ". Please action"
DoCmd.RunCommand acCmdSaveRecord
strEmail = Left(strEmail, Len(strEmail) - 1)
DoCmd.SendObject , , , strEmail, , , strSubject, strBody, True
DoCmd.OpenForm "frmSwitchboard"
DoCmd.Close acForm, "frmSelectNew"
End Sub