Hi folks,
I have a module that calls a recordset and emails to the relevant person. The problem I have is that I can't manage to get all the data into the message body, the variable 'strmessage' fails to grab the data.
If anyone can see what's wrong with my code any assistance/advice would be muchly appreciated.
Function fSendEmail()
On Error GoTo fSendMail_Err
Dim rs As DAO.Recordset
Dim strEmailTo As String
Dim strForename As String
Dim strusername As String
Dim strpassword As String
Dim strtext1 As String
Dim strtext2 As String
Dim strtext3 As String
Dim strmessage As String
Set rs = CurrentDb.OpenRecordset("SELECT * FROM StaffPasswords where emailed = 0")
rs.MoveFirst
While Not rs.EOF
If strEmailTo <> "" Then
strEmailTo = strEmailTo & "; " & rs!EMAIL
Else
strEmailTo = rs!EMAIL
End If
If strForename <> "" Then
strForename = strForename & "; " & rs![Employee First Name]
Else
strForename = rs![Employee First Name]
End If
If strusername <> "" Then
strusername = strusername & "; " & rs!UserName
Else
strusername = rs!UserName
End If
If strpassword <> "" Then
strpassword = strpassword & ": " & rs!Password
Else
strpassword = rs!Password
End If
If strmessage <> "" Then
strmessage = "Dear " & rs![Employee First Name] & ", Your username is " & rs!UserName & " and your password is " & rs!Password
Else
End If
rs.MoveNext
Wend
DoCmd.SendObject , "", "", strEmailTo, "", "", "IMPORTANT-IRIS/Unit-e User Account", strmessage, True, """"""
fSendMail_Exit:
Exit Function
fSendMail_Err:
MsgBox Err.Number & " " & Err.Description, vbOKOnly + vbExclamation
Resume fSendMail_Exit:
End Function
I have a module that calls a recordset and emails to the relevant person. The problem I have is that I can't manage to get all the data into the message body, the variable 'strmessage' fails to grab the data.
If anyone can see what's wrong with my code any assistance/advice would be muchly appreciated.
Function fSendEmail()
On Error GoTo fSendMail_Err
Dim rs As DAO.Recordset
Dim strEmailTo As String
Dim strForename As String
Dim strusername As String
Dim strpassword As String
Dim strtext1 As String
Dim strtext2 As String
Dim strtext3 As String
Dim strmessage As String
Set rs = CurrentDb.OpenRecordset("SELECT * FROM StaffPasswords where emailed = 0")
rs.MoveFirst
While Not rs.EOF
If strEmailTo <> "" Then
strEmailTo = strEmailTo & "; " & rs!EMAIL
Else
strEmailTo = rs!EMAIL
End If
If strForename <> "" Then
strForename = strForename & "; " & rs![Employee First Name]
Else
strForename = rs![Employee First Name]
End If
If strusername <> "" Then
strusername = strusername & "; " & rs!UserName
Else
strusername = rs!UserName
End If
If strpassword <> "" Then
strpassword = strpassword & ": " & rs!Password
Else
strpassword = rs!Password
End If
If strmessage <> "" Then
strmessage = "Dear " & rs![Employee First Name] & ", Your username is " & rs!UserName & " and your password is " & rs!Password
Else
End If
rs.MoveNext
Wend
DoCmd.SendObject , "", "", strEmailTo, "", "", "IMPORTANT-IRIS/Unit-e User Account", strmessage, True, """"""
fSendMail_Exit:
Exit Function
fSendMail_Err:
MsgBox Err.Number & " " & Err.Description, vbOKOnly + vbExclamation
Resume fSendMail_Exit:
End Function