Elmobram22
Registered User.
- Local time
- Today, 12:45
- Joined
- Jul 12, 2013
- Messages
- 165
Hi all,
I have changed some VBA code for an email within access through outlook. I have used this code succesfully before and it is tied to buttons within my database without an issue. The problem I have now though is the HTMLbody section is coming back with -1 rather than the information it should. The email is populated from data within a form and the code looks like this...
Private Sub Command28_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim sSql As String
Dim sFirst As String
Dim sLast As String
Dim sEmail As String
sSql = "SELECT FirstName, LastName , email, LeftAV "
sSql = sSql & "FROM tblStaff "
sSql = sSql & "WHERE [LeftAV] = no;"
Set db = CurrentDb
Set rst = db.OpenRecordset(sSql, dbOpenSnapshot)
If rst.RecordCount > 0 Then
rst.MoveFirst
Do While Not rst.EOF
sFirst = rst.Fields("FirstName")
sLast = rst.Fields("LastName")
sEmail = rst.Fields("email")
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Dim strPath As String
strPath = "\\25.45.65.15\k\logo.jpg"
If strPath <> "" Then
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.To = sEmail
.Subject = "Meeting"
.HTMLBody = "Hi " & [sFirst] & "," & "<br>" & "<br>" _
& "The date of the next " & [Combo4].Column(1) & " at " & [Combo0].Column(1) & " is at " & [pbTime] & " on " & [pbDate] < br > " & " < br > "" _
& "All are welcome to attend. Those who work regular shifts at the home will be paid for their time." < br > " & " < br > "" _
& "Please contact the Team Leader to let them know if you will be attending. Thank you." < br > " & " < br > "" _
& "Kind regards," & "<br>" & "<br>" _
& "Our Place Ltd" & "<br>" & "<br>"
.Display
End With
Else
MsgBox "No file matching " & strPath & " found. Please make sure the file is complete." & vbCrLf & _
"Processing terminated."
Exit Sub
End If
rst.MoveNext
Loop
End If
rst.Close
Set rst = Nothing
MsgBox "Emails Sent"
End Sub
I have changed some VBA code for an email within access through outlook. I have used this code succesfully before and it is tied to buttons within my database without an issue. The problem I have now though is the HTMLbody section is coming back with -1 rather than the information it should. The email is populated from data within a form and the code looks like this...
Private Sub Command28_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim sSql As String
Dim sFirst As String
Dim sLast As String
Dim sEmail As String
sSql = "SELECT FirstName, LastName , email, LeftAV "
sSql = sSql & "FROM tblStaff "
sSql = sSql & "WHERE [LeftAV] = no;"
Set db = CurrentDb
Set rst = db.OpenRecordset(sSql, dbOpenSnapshot)
If rst.RecordCount > 0 Then
rst.MoveFirst
Do While Not rst.EOF
sFirst = rst.Fields("FirstName")
sLast = rst.Fields("LastName")
sEmail = rst.Fields("email")
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Dim strPath As String
strPath = "\\25.45.65.15\k\logo.jpg"
If strPath <> "" Then
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.To = sEmail
.Subject = "Meeting"
.HTMLBody = "Hi " & [sFirst] & "," & "<br>" & "<br>" _
& "The date of the next " & [Combo4].Column(1) & " at " & [Combo0].Column(1) & " is at " & [pbTime] & " on " & [pbDate] < br > " & " < br > "" _
& "All are welcome to attend. Those who work regular shifts at the home will be paid for their time." < br > " & " < br > "" _
& "Please contact the Team Leader to let them know if you will be attending. Thank you." < br > " & " < br > "" _
& "Kind regards," & "<br>" & "<br>" _
& "Our Place Ltd" & "<br>" & "<br>"
.Display
End With
Else
MsgBox "No file matching " & strPath & " found. Please make sure the file is complete." & vbCrLf & _
"Processing terminated."
Exit Sub
End If
rst.MoveNext
Loop
End If
rst.Close
Set rst = Nothing
MsgBox "Emails Sent"
End Sub