Help - I am trying to wrap my head around some advanced stuff and I think my grey matter has turned to mush....
I am using Access 2003 and I have code which generates an email in Lotus notes from the database. It works really well and we have been using it for a couple of years across a couple of databases. Here's the rub, the email is plain text and I am being asked by management to "jazz" it up with bold font and perhaps tables to display the data being sent.
I am trying to create the email in rich text now so that I can generate bold font and a table. I am working with bold font first because I thought it would be easier, but.....I am getting no where fast.
This is the orignal code, without my modifications:
And here is what I am tryng to do:
But I get "object variable with block variable not set" errors and type mismatch and I am so confused..... Can anyone give me a prod in the right direction?
I am using Access 2003 and I have code which generates an email in Lotus notes from the database. It works really well and we have been using it for a couple of years across a couple of databases. Here's the rub, the email is plain text and I am being asked by management to "jazz" it up with bold font and perhaps tables to display the data being sent.
I am trying to create the email in rich text now so that I can generate bold font and a table. I am working with bold font first because I thought it would be easier, but.....I am getting no where fast.
This is the orignal code, without my modifications:
Code:
Public Sub SendQtrNotesMail(Subject As String, Recipient As String, WL As String, SQA As String, _
DeltaC As String, SOR As String, ADR As String, TDR As String, AIDPU As String, Tagged As String, UnTagged As String, SafetyNote As String, QualityNote As String, _
ProdNote As String, SaveIt As Boolean)
'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 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 or using above password you can use other mailboxes.
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 up the new mail document
Set MailDoc = Maildb.createdocument
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.Body = WL & vbCrLf & SQA & vbCrLf & DeltaC & vbCrLf & SOR & vbCrLf & ADR & vbCrLf & TDR & vbCrLf & AIDPU & vbCrLf & Tagged & vbCrLf & UnTagged & vbCrLf & _
SafetyNote & vbCrLf & QualityNote & vbCrLf & ProdNote
MailDoc.SaveMessageOnSend = SaveIt
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.Send 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
And here is what I am tryng to do:
Code:
Public Sub SendQtrNotesMail(Subject As String, Recipient As String, WL As String, SQA As String, _
DeltaC As String, SOR As String, ADR As String, TDR As String, SafetyTitle As String, SafetyNote As String, _
QualityTitle As String, QualityNote As String, ProdTitle As String, ProdNote As String, SaveIt As Boolean)
'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 Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
Dim richStyle As Object
Dim rtStyle As NotesRichTextStyle
Dim rtItem As NotesRichTextItem
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
Set rtStyle = Session.CreateRichTextStyle
'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 or using above password you can use other mailboxes.
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 up the new mail document
Set MailDoc = Maildb.createdocument
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.body = WL & vbCrLf & SQA & vbCrLf & DeltaC & vbCrLf & ADR & vbCrLf & TDR & vbCrLf & _
richStyle.Bold = True
Call rtItem.AppendStyle(rtStyle)
MailDoc.body = SafetyTitle & vbCrLf & _
richStyle.Bold = False
MailDoc.body = SafetyNote & vbCrLf & _
richStyle.Bold = True
Call rtItem.AppendStyle(rtStyle)
MailDoc.body = QualityTitle & vbCrLf & _
richStyle.Bold = False
MailDoc.body = QualityNote & vbCrLf & _
richStyle.Bold = True
Call rtItem.AppendStyle(rtStyle)
MailDoc.body = ProdTitle & vbCrLf & _
richStyle.Bold = False
MailDoc.body = ProdNote
MailDoc.SaveMessageOnSend = SaveIt
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.Send 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
But I get "object variable with block variable not set" errors and type mismatch and I am so confused..... Can anyone give me a prod in the right direction?