473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Automation Weirdness with Outlook

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
2 2640
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: qwweeeit | last post by:
Hi all, Elliot Temple on the 1 June wrote: > How do I make Python press a button on a webpage? I looked at > urllib, but I only see how to open a URL with that. I searched > google but no...
2
by: Lauren Quantrell | last post by:
Using Outlook Automation, is there a way to insert a graphic in the body of an e-mail so that it appears at the top of an email? lq
2
by: Giganews | last post by:
I am currently working on an Outlook automation module in an Access 97 database. All is working well except now the client wants the generic email body to contain certain sections in red text and...
0
by: salad | last post by:
I'm on A97 and have Outlook 2003 on the computer. There's some generic code at Tony Toew's site and at MS and on the web that's very similar....but I can't make it work. I want to use late...
9
NeoPa
by: NeoPa | last post by:
In VBA (I expect VB would be similar) controlling another Office Application (Automation) can be done using the following steps : Ensure the Reference (VBA Window / Tools / References) has been...
1
by: =?Utf-8?B?cm9i?= | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
1
by: allbelonging | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
10
by: cj2 | last post by:
I open a word template in VB and add values to the bookmarks then save the document as as pdf. When I then go to close the document it pops up a save as dialog box. It's already saved the...
0
by: madihamir | last post by:
Iam new to .net and have gotten assignment for make the class library to automate the outlook I have tried to done it but i've to make the Handlers also . Detecting an methods for receiving and...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.