J
John Strung
This is driving me nuts. I have some code that runs right every second time
and I can't figure out why!
The purpose of the code is to automatically address and format an e-mail
message from a button on an MS Access card. The code correctly takes the
name of the addressee from the card, and the inserts it and the contents of
the Re: line. It then inserts an additional two or three lines of
information from the Access card into the message field.
The next step in the code is to insert a signature file entitled
"letterhead" which is a graphic of our letterhead above the three lines of
text in the message field. The next part of the codes moves the cursor down
below the text and is supposed to insert a second signature file, this time
called "full signature" at the bottom of the message which includes the name
of the sender and some sender specific information. The two signature files
are simply in the Outlook appliction and are named "letterhead" and "full
signature".
Everything works perfectly except that every second time the code is run (by
clicking on the button on the Access card), the code inserts the
"letterhead" signature at the bottom instead of the "full signature", so we
end up with the "letterhead signature" twice (at the top and bottom) and no
"full signature".
Any help would be appreciated. The code is as follows:
-------------------
Dim olApp As Object
Dim objNewMail As Object
Dim objONewmail As Object
Dim AddressString As String, SubjectString As String
Dim bodystring1 As String, bodystring2 As String, bodystring3 As String
Set olApp = New Outlook.Application
Set objONewmail = olApp.CreateItem(olMailItem)
Set objNewMail = CreateObject("REDEMPTION.SafeMailItem") 'Circumvents
Outlook Security Patch
objNewMail.Item = objONewmail
With objNewMail
'Gets various information from MS Access and inserts it
into a mail message:
AddressString = CStr(Me!)
SubjectString = CStr([File Name])
bodystring1 = "Our File Number: " & CStr([File Number]) & Chr(10)
bodystring2 = ""
bodystring3 = ""
If IsNull(Me![Claimno]) = 0 Then bodystring2 = "Your Claim Number: " &
CStr(Me![Claimno]) & Chr(10)
If IsNull(Me![DateLoss]) = 0 Then bodystring3 = "Date of Loss: " &
CStr(Me![DateLoss]) & Chr(10)
bodystring1 = bodystring1 & bodystring2 & bodystring3 &
"-------------------------" & Chr(10) & Chr(10) & Chr(10)
..Recipients.Add AddressString
..Recipients.ResolveAll
..Subject = SubjectString
..Body = bodystring1
..Display
'The next section inserts the "letterhead" signature file above
the three lines of text in the body of the message:
Dim objOutlook As Outlook.Application
Dim ObjCtl As Office.CommandBarControl
Dim ObjPop As Office.commandBarPopup
Dim ObjCB As Office.CommandBar
Dim ObjItem As Object
Set objOutlook = CreateObject("Outlook.Application")
Set ObjCB = objOutlook.ActiveInspector.CommandBars("Menu Bar")
Set ObjPop = ObjCB.Controls("Insert")
Set ObjPop = ObjPop.Controls("Signature")
Set ObjCtl = ObjPop.Controls.Item("letterhead")
ObjCtl.Execute
Set objOutlook = Nothing
Set ObjCtl = Nothing
Set ObjPop = Nothing
Set ObjCB = Nothing
Set ObjItem = Nothing
'Next section moves Cursor to bottom of message before inserting signature
x = 6
Dim sInspector
Dim plaintexteditor
Set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Outlook.ActiveInspector
Set plaintexteditor = sInspector.plaintexteditor
plaintexteditor.CaretPosY = x
'The next section inserts the "full signature" signature file at the
bottom of the message
Dim objOutlook2 As Outlook.Application
Dim ObjCtl2 As Office.CommandBarControl
Dim ObjPop2 As Office.commandBarPopup
Dim ObjCB2 As Office.CommandBar
Dim ObjItem2 As Object
Set objOutlook2 = CreateObject("Outlook.Application")
Set ObjCB2 = objOutlook2.ActiveInspector.CommandBars("Menu Bar")
Set ObjPop2 = ObjCB2.Controls("Insert")
Set ObjPop2 = ObjPop2.Controls("Signature")
Set ObjCtl2 = ObjPop2.Controls.Item("Full Signature")
Set ObjCtl2 = ObjPop2.Controls.Item("Full Signature")
ObjCtl2.Execute
Set objOutlook2 = Nothing
Set ObjCtl2 = Nothing
Set ObjPop2 = Nothing
Set ObjCB2 = Nothing
Set ObjItem2 = Nothing
'resets the cursor position to above the signature for text entry
x = 6
If IsNull(Me![Claimno]) = True Then x = x - 1
If IsNull(Me![DateLoss]) = True Then x = x - 1
'Dim sInspector
'Dim plaintexteditor
Set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Outlook.ActiveInspector
Set plaintexteditor = sInspector.plaintexteditor
plaintexteditor.CaretPosY = x
End With
Dim utils
Set utils = CreateObject("Redemption.MAPIUtils")
Exit Sub
and I can't figure out why!
The purpose of the code is to automatically address and format an e-mail
message from a button on an MS Access card. The code correctly takes the
name of the addressee from the card, and the inserts it and the contents of
the Re: line. It then inserts an additional two or three lines of
information from the Access card into the message field.
The next step in the code is to insert a signature file entitled
"letterhead" which is a graphic of our letterhead above the three lines of
text in the message field. The next part of the codes moves the cursor down
below the text and is supposed to insert a second signature file, this time
called "full signature" at the bottom of the message which includes the name
of the sender and some sender specific information. The two signature files
are simply in the Outlook appliction and are named "letterhead" and "full
signature".
Everything works perfectly except that every second time the code is run (by
clicking on the button on the Access card), the code inserts the
"letterhead" signature at the bottom instead of the "full signature", so we
end up with the "letterhead signature" twice (at the top and bottom) and no
"full signature".
Any help would be appreciated. The code is as follows:
-------------------
Dim olApp As Object
Dim objNewMail As Object
Dim objONewmail As Object
Dim AddressString As String, SubjectString As String
Dim bodystring1 As String, bodystring2 As String, bodystring3 As String
Set olApp = New Outlook.Application
Set objONewmail = olApp.CreateItem(olMailItem)
Set objNewMail = CreateObject("REDEMPTION.SafeMailItem") 'Circumvents
Outlook Security Patch
objNewMail.Item = objONewmail
With objNewMail
'Gets various information from MS Access and inserts it
into a mail message:
AddressString = CStr(Me!)
SubjectString = CStr([File Name])
bodystring1 = "Our File Number: " & CStr([File Number]) & Chr(10)
bodystring2 = ""
bodystring3 = ""
If IsNull(Me![Claimno]) = 0 Then bodystring2 = "Your Claim Number: " &
CStr(Me![Claimno]) & Chr(10)
If IsNull(Me![DateLoss]) = 0 Then bodystring3 = "Date of Loss: " &
CStr(Me![DateLoss]) & Chr(10)
bodystring1 = bodystring1 & bodystring2 & bodystring3 &
"-------------------------" & Chr(10) & Chr(10) & Chr(10)
..Recipients.Add AddressString
..Recipients.ResolveAll
..Subject = SubjectString
..Body = bodystring1
..Display
'The next section inserts the "letterhead" signature file above
the three lines of text in the body of the message:
Dim objOutlook As Outlook.Application
Dim ObjCtl As Office.CommandBarControl
Dim ObjPop As Office.commandBarPopup
Dim ObjCB As Office.CommandBar
Dim ObjItem As Object
Set objOutlook = CreateObject("Outlook.Application")
Set ObjCB = objOutlook.ActiveInspector.CommandBars("Menu Bar")
Set ObjPop = ObjCB.Controls("Insert")
Set ObjPop = ObjPop.Controls("Signature")
Set ObjCtl = ObjPop.Controls.Item("letterhead")
ObjCtl.Execute
Set objOutlook = Nothing
Set ObjCtl = Nothing
Set ObjPop = Nothing
Set ObjCB = Nothing
Set ObjItem = Nothing
'Next section moves Cursor to bottom of message before inserting signature
x = 6
Dim sInspector
Dim plaintexteditor
Set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Outlook.ActiveInspector
Set plaintexteditor = sInspector.plaintexteditor
plaintexteditor.CaretPosY = x
'The next section inserts the "full signature" signature file at the
bottom of the message
Dim objOutlook2 As Outlook.Application
Dim ObjCtl2 As Office.CommandBarControl
Dim ObjPop2 As Office.commandBarPopup
Dim ObjCB2 As Office.CommandBar
Dim ObjItem2 As Object
Set objOutlook2 = CreateObject("Outlook.Application")
Set ObjCB2 = objOutlook2.ActiveInspector.CommandBars("Menu Bar")
Set ObjPop2 = ObjCB2.Controls("Insert")
Set ObjPop2 = ObjPop2.Controls("Signature")
Set ObjCtl2 = ObjPop2.Controls.Item("Full Signature")
Set ObjCtl2 = ObjPop2.Controls.Item("Full Signature")
ObjCtl2.Execute
Set objOutlook2 = Nothing
Set ObjCtl2 = Nothing
Set ObjPop2 = Nothing
Set ObjCB2 = Nothing
Set ObjItem2 = Nothing
'resets the cursor position to above the signature for text entry
x = 6
If IsNull(Me![Claimno]) = True Then x = x - 1
If IsNull(Me![DateLoss]) = True Then x = x - 1
'Dim sInspector
'Dim plaintexteditor
Set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Outlook.ActiveInspector
Set plaintexteditor = sInspector.plaintexteditor
plaintexteditor.CaretPosY = x
End With
Dim utils
Set utils = CreateObject("Redemption.MAPIUtils")
Exit Sub