I have a routine that uses Late Binding to create a email and put it
into the DRAFTS folder of Outlook. It only works if Outlook is already
launched (Opened by me clicking on my desktop ICON manually). If
Outlook is not previously opened, I'm not sure if they are getting put
into the Inbox folder or are being actually sent and then get received
by me email server and sent down to me (I just see them appear in the
inbox - but not immediately).
Here is the routine ... can anybody help me see my flaw?
I've left in all my commented out attempts to "fix" this problem.
Thanks so much.
SueB
'*================================================ ======*
Public Sub BldEmail(lngDogRegNbr As Long, _
strFormalName As String, _
strOwner As String, _
strAltOwner As Variant, _
dtProcessedDt As Date, _
strUval As String, _
strEmail As String)
On Error GoTo Err_BldEmail
'Dim objOutlook As Outlook.Application
'Dim objNameSpace As Outlook.NameSpace
'Dim objDrafts As MAPIFolder
'Dim objItem As Outlook.MailItem
Dim objOutlook As Object
Dim objNameSpace As Object
Dim objDrafts As Object
Dim objItem As Object
Dim strBody As String
'Set objOutlook = New Outlook.Application
Set objOutlook = CreateObject("Outlook.Application")
Set objItem = objOutlook.CreateItem(0) 'olMailItem = 0
'Get the MAPI reference ...
'Set objNameSpace = objNameSpace.GetNameSpace("MAPI")
Set objNameSpace = objOutlook.GetNameSpace("MAPI")
'Pick up the Drafts folder ...
'Set objDrafts = objNameSpace.GetDefaultfolder(olFolderDrafts)
Set objDrafts = objNameSpace.GetDefaultFolder(12)
'Add Mail item ...
'Set objItem = objDrafts.Items.Add
'Set objItem = objDrafts.Add
'Set the mail item properties ...
objItem.To = strEmail
objItem.Subject = "CDSP Dog Registration Acknowledgement (" & _
lngDogRegNbr & ")"
'objItem.BodyFormat = 2 'olFormatHTML = 2
'Build the email body text...
'Colors:
' Black = #000000
' Red = #ff0000
' Dk. Blue = #000080
' Lt. Grey = #c0c0c0
strBody = "<HTML>" & _
"<BODY>"
strBody = strBody & _
"<FONT FACE=""Arial"" style=""font-size: 12pt""
color=""#000000"">" & _
"St. Hubert's is happy to confirm the receipt " & _
"of your registration request.</FONT>" & _
"<BR><BR>"
strBody = strBody & _
"<TABLE WIDTH=75% BORDER RULES=ALL
BORDERCOLOR=""#C0C0C0"">"
'Dog Registration Number Row
strBody = strBody & _
"<TR ALIGN=LEFT>" & _
"<TD WIDTH=5.2%>" & _
"<FONT FACE=""Georgia"" style=""font-size: 12pt""
color=""#000000"">" & _
"*<BR><B><I>Dog Registration Number</I></B><BR>*" & _
"</FONT>" & _
"</TD>" & _
"<TD ALIGN=CENTER WIDTH=94.8% BGCOLOR=""#FFFF80"">" & _
"<FONT FACE=""Georgia"" style=""font-size: 18pt""
color=""#FF0000"">" & _
"<B>" & lngDogRegNbr & "</B>" & _
"</FONT>" & _
"</TD>" & _
"</TR>"
'Dog Name Row
strBody = strBody & _
"<TR ALIGN=LEFT>" & _
"<TD WIDTH=5.2%>" & _
"<FONT FACE=""Georgia"" style=""font-size: 12pt""
color=""#000000"">" & _
"*<BR><B><I>Dog Name</I></B><BR>*" & _
"</FONT>" & _
"</TD>" & _
"<TD WIDTH=94.8%>" & _
"<FONT FACE=""Georgia"" style=""font-size: 12pt""
color=""#000000"">" & _
strFormalName & _
"</FONT>" & _
"</TD>" & _
"</TR>"
'Owner Row
strBody = strBody & _
"<TR ALIGN=LEFT>" & _
"<TD WIDTH=5.2%>" & _
"<FONT FACE=""Georgia"" style=""font-size: 12pt""
color=""#000000"">" & _
"*<BR><B><I>Owner</I></B><BR>*" & _
"</FONT>" & _
"</TD>" & _
"<TD WIDTH=94.8%>" & _
"<FONT FACE=""Georgia"" style=""font-size: 12pt""
color=""#000000"">" & _
strOwner & "<BR>" & strAltOwner & _
"</FONT>" & _
"</TD>" & _
"</TR>"
'Issue Date Row
strBody = strBody & _
"<TR ALIGN=LEFT>" & _
"<TD WIDTH=5.2%>" & _
"<FONT FACE=""Georgia"" style=""font-size: 12pt""
color=""#000000"">" & _
"*<BR><B><I>Issue Date</I></B><BR>*" & _
"</FONT>" & _
"</TD>" & _
"<TD WIDTH=94.8%>" & _
"<FONT FACE=""Georgia"" style=""font-size: 12pt""
color=""#000000"">" & _
dtProcessedDt & _
"</FONT>" & _
"</TD>" & _
"</TR>"
'End Table
strBody = strBody & _
"</TABLE>" & _
"<BR><BR>"
'Text following table
strBody = strBody & _
"<FONT FACE=""Arial"" style=""font-size: 12pt""
color=""000000"">" & _
"Please print and save this letter, or otherwise record
the " & _
"Dog Registration Number, as no other notice will be sent
to you." & _
"</FONT>" & _
"<BR><BR>"
strBody = strBody & _
"<FONT FACE=""Arial"" style=""font-size: 12pt""
color=""FF0000"">" & _
"The dog Registration Number must be presented to the host
" & _
"organization when entering a trial. If this number is
not provided, " & _
"your trial scores will not be reported to CDSP for
processing." & _
"</FONT>" & _
"<BR><BR><BR>"
'Signature
strBody = strBody & _
"<FONT FACE=""Freestyle Script"" style=""font-size: 22pt""
" & _
"color=""000080"">" & _
strUval & _
"</FONT>" & _
"<BR>"
strBody = strBody & _
"<FONT FACE=""Arial"" style=""font-size: 12pt""
color=""000000"">" & _
"St. Hubert's Companion Dog Sports Program Coordinator" &
_
"</FONT>" & _
"<BR>"
'Close Email
strBody = strBody & _
"</BODY>" & _
"</HTML>"
'Set the body of the mail ...
objItem.HTMLBody = strBody
'Save the email in the Drafts Folder ...
objItem.Save
'Clear object ...
Set objItem = Nothing
Set objOutlook = Nothing
Exit_BldEmail:
Exit Sub
Err_BldEmail:
Call ShowError("CommonProcs", "BldEmail", Err.Number,
Err.Description)
Resume Exit_BldEmail
End Sub
Regards,
SueB
*** Sent via Developersdex http://www.developersdex.com ***