Within an Access database I've got a procedure that is called at the end of each month for sending an email via Lotus Notes to a group of users. The email basically contains details of any expired libraries that are on our system. However, although the procedure of sending the email via Lotus Notes works fine I can't seem to be able to work out how to use HTML tags to format the email. Is anybody able to shed any light on how this can be done.
Below is the code for the function that sends the email:Function MailExpLibs()
Dim Subject As String
Dim Attachment As String
Dim Recipient As String
Dim BodyText As String
Dim SaveIt As Boolean
Dim dbs As Database
Dim Rs As Recordset
Dim Rst As Recordset
Dim CountRs As Integer
Dim CountRst As Integer
'This function will send a mail and attachment if neccessary to the recipient including the body text.
'Requires that notes client is installed on the system.
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'The current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession"
'Get the sessions username and then calculate the mail file name.
'You may or may not need this as for MailDBname with some systems you can pass an empty string
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "
)) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set the message for the BodyText
BodyText = "Library Control System - Expired Libraries" & vbCrLf & vbCrLf
BodyText = "The following libraries have expired:" & vbCrLf & vbCrLf
Set dbs = CurrentDb
'open recordset to retrieve system names
Set Rs = dbs.OpenRecordset("SELECT * FROM tblSystemName;", dbOpenDynaset)
With Rs
CountRs = Rs.RecordCount
If CountRs > 0 Then .MoveLast
Do While CountRs > 0
''for each system name open a recordset to retrieve the expired library lists
Set Rst = dbs.OpenRecordset("SELECT * FROM tblLibNew WHERE LibStatus = 'E';", dbOpenDynaset)
With Rst
CountRst = Rst.RecordCount
If Count = 0 Then
BodyText = "There are no expired "
If CountRst >= 1 Then
BodyText = BodyText & "CUSV71AA1" & vbCrLf
BodyText = BodyText & "CUSV71AA2" & vbCrLf
BodyText = BodyText & "CUSV71AA3" & vbCrLf
End If
End With
BodyText = BodyText & vbCrLf
BodyText = BodyText & "Open the EMT Library Control Database and take the appropriate action."
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = "someone@xyzcompany.com"
MailDoc.Subject = "Library Control System"
MailDoc.body = BodyText
MailDoc.SAVEMESSAGEONSEND = SaveIt
'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment"
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment"
MailDoc.CREATERICHTEXTITEM ("Attachment"
End If
'Send the document
MailDoc.SEND 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
Set Rst = Nothing
Set dbs = Nothing
End Function
Below is the code for the function that sends the email:Function MailExpLibs()
Dim Subject As String
Dim Attachment As String
Dim Recipient As String
Dim BodyText As String
Dim SaveIt As Boolean
Dim dbs As Database
Dim Rs As Recordset
Dim Rst As Recordset
Dim CountRs As Integer
Dim CountRst As Integer
'This function will send a mail and attachment if neccessary to the recipient including the body text.
'Requires that notes client is installed on the system.
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'The current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession"
'Get the sessions username and then calculate the mail file name.
'You may or may not need this as for MailDBname with some systems you can pass an empty string
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set the message for the BodyText
BodyText = "Library Control System - Expired Libraries" & vbCrLf & vbCrLf
BodyText = "The following libraries have expired:" & vbCrLf & vbCrLf
Set dbs = CurrentDb
'open recordset to retrieve system names
Set Rs = dbs.OpenRecordset("SELECT * FROM tblSystemName;", dbOpenDynaset)
With Rs
CountRs = Rs.RecordCount
If CountRs > 0 Then .MoveLast
Do While CountRs > 0
''for each system name open a recordset to retrieve the expired library lists
Set Rst = dbs.OpenRecordset("SELECT * FROM tblLibNew WHERE LibStatus = 'E';", dbOpenDynaset)
With Rst
CountRst = Rst.RecordCount
If Count = 0 Then
BodyText = "There are no expired "
If CountRst >= 1 Then
BodyText = BodyText & "CUSV71AA1" & vbCrLf
BodyText = BodyText & "CUSV71AA2" & vbCrLf
BodyText = BodyText & "CUSV71AA3" & vbCrLf
End If
End With
BodyText = BodyText & vbCrLf
BodyText = BodyText & "Open the EMT Library Control Database and take the appropriate action."
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = "someone@xyzcompany.com"
MailDoc.Subject = "Library Control System"
MailDoc.body = BodyText
MailDoc.SAVEMESSAGEONSEND = SaveIt
'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment"
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment"
MailDoc.CREATERICHTEXTITEM ("Attachment"
End If
'Send the document
MailDoc.SEND 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
Set Rst = Nothing
Set dbs = Nothing
End Function