I'm using this function in a bulk email form which allows personalization
within the bulk email somewhat like the mailmerge in Word. In the email
message users can choose to insert field contents which are put in between $$
signs. Eg - $$Lastname$$ would insert the recipients lastname into the
message. Hence I am using replaceall to look for words between two $$ signs &
replace them with the contents of a field. Once again I'd like to say that at
this point even a simple replaceall("test","d","t") gives me the same error
message. In fact using this in a blank database also gives me the same error.
What do you mean by using wizards in this function? How do I do that?
Dim sBaseMessage As String
Dim sActualMessage As String
Dim sFieldToReplace As String
Dim sFieldPosition As Integer
Dim sTempReplace As Variant
Dim replaceflag
Dim StartPos As Integer
Dim EndPos As Integer
Set cnn = CurrentProject.Connection
sBaseMessage = txtMessage
Set rs = New ADODB.Recordset
rs.Open Source:="StudentEmail", _
ActiveConnection:=cnn, _
CursorType:=adOpenDynamic, _
LockType:=adLockOptimistic
rs.MoveFirst
While Not rs.EOF
sActualMessage = sBaseMessage
While InStr(sActualMessage, "$$")
sFieldPosition = InStr(sActualMessage, "$$")
sEndFieldPosition = InStr(sFieldPosition + 1,
sActualMessage, "$$")
sFieldToReplace = Mid$(sActualMessage, sFieldPosition + 2,
sEndFieldPosition - (sFieldPosition + 2))
'sActualMessage = ReplaceAll(sActualMessage,
DLookup(sFieldToReplace, "student_Email", "student_ID=" &
CStr(rs("student_id"))), "$$" & sFieldToReplace & "$$")
sTempReplace = IIf(IsNull(rs(sFieldToReplace)), "Blank",
rs(sFieldToReplace))
sActualMessage = ReplaceAll(sActualMessage,
CStr(sTempReplace), "$$" & sFieldToReplace & "$$")
Wend
If chkTestMode.Value = False Then
nSendFlag = SendEmail(rs("Student_Last_name"),
rs("Student_First_name"), txtFrom, Trim(rs("student_Email")), sActualMessage,
txtSubject)
Else
If MsgBox("TO: " & rs("Student_Email") & vbCrLf & vbCrLf & _
"SUBJECT: " & txtSubject & vbCrLf & vbCrLf & _
sActualMessage & vbCrLf & vbCrLf & "Click OK to continue or
CANCEL to exit test mode.", vbInformation + vbOKCancel, "Test Mode Message
Display") = vbCancel Then
cmdCancel.Tag = "stop"
End If
End If
If cmdCancel.Tag = "cancel" Then
Command24.Caption = "Send"
nSendFlag = SendEmail(rs("Student_Last_name"),
rs("Student_First_name"), txtFrom, txtFrom, "You cancelled this operation
before it completed. However, before it was cancelled, the message was sent
to the following recipients: " & sMailStatus, "Census bulk email report for:
" & txtSubject & " (Cancelled by user)")
MsgBox "The group email has been cancelled.",
vbInformation
cmdCancel.Tag = ""
If InvalidFound = True Then DoCmd.OpenReport
"InvalidEmail", acViewPreview
Exit Sub
End If
If cmdCancel.Tag = "stop" Then
Command24.Caption = "Send"
MsgBox "Test mode has been exited. To send your email,
turn off test mode and click the Send button again.", vbInformation
cmdCancel.Tag = ""
If InvalidFound = True Then DoCmd.OpenReport
"InvalidEmail", acViewPreview
Exit Sub
End If
DoEvents
Command24.Caption = rs("Student_Email")
rs.MoveNext
Wend
rs.Close
If chkTestMode.Value = False Then
nSendFlag = SendEmail("", "", txtFrom, txtFrom, "Your message
was sent to the following recipients: " & sMailStatus & vbCrLf & vbCrLf &
"The following could not be sent: " & sNoMailStatus, "Accessibility bulk
email report for: " & txtSubject)
MsgBox "Your message has been sent.", vbInformation
Else
MsgBox "Test mode has been exited. To send your email, turn off
test mode and click the Send button again.", vbInformation
End If
'End If
Else
If chkTestMode.Value = False Then
nSendFlag = SendEmail("", "", txtFrom, txtTo, txtMessage, txtSubject)
MsgBox "Your message has been sent.", vbInformation
Else
MsgBox "There is no test mode for sending mail to a single
recipient.", vbInformation
cmdCancel.Tag = ""
Exit Sub
End If
End If
Command24.Caption = "Send"
cmdCancel.Tag = ""
DoCmd.Close
End Sub