By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,656 Members | 1,917 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,656 IT Pros & Developers. It's quick & easy.

Automation Weirdness with Outlook

P: n/a
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 ***
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I forgot to add ...

I am running Access 2003 and Outlook 2003.

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #2

P: n/a
Susan Bricker <sl*****@verizon.net> wrote in news:Ih1bf.3$XA4.1610
@news.uswest.net:
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).


|SNIPS|

I think we use .Close olSave to save to the draft's folder?

In general, perhaps your code does too much in terms of Outlook (not in
creating your message)?

This saves a messages in my Drafts folder. I use 2003-2003, as you.

Public Sub TestSaveADraft()

Dim objOutlook As Outlook.Application
Dim objItem As Outlook.MailItem

Set objOutlook = New Outlook.Application
Set objItem = objOutlook.CreateItem(olMailItem)

With objItem
.To = "ly******@yahoo.ca"
.Subject = "Subject"
.Body = "Body"
.Close olSave
End With
Set objItem = Nothing

' personal pref here
' outlook may go through some machinations about deleting when quitted

' objOutlook.Quit

Set objOutlook = Nothing

End Sub

I am guessing that you need the message in drafts and this is why you use
the ugly, slow and ponderous Outlook instead of the beautiful, swift and
sleek CDO?

--
Lyle Fairfield
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.