Printout method for HTML messages

K

Kristy

Hi

I have created a com addin for Outlook 2000/XP. Bascially the
application creates HTML emails using templates for marketing
purposes, they almost always contain embedded graphics (logo's etc).

Many of my customers like to automatically print Sent messages that
meet certain criteria, one of these is if any attachments are
included.

Currently I use a custom "button" called Send and Print that when
clicked will check for attachments, if any exist I add an attachments
list to the bottom of the message (since HTML messages don't print
attachment icons), then create a custom tag (so that I can identify it
later) and send it.

There is an event on the Sent Items folder which checks new items for
my custom field, if it exists then the message is printed using the
item.printout method.

The problem is that if I don't display it it prints but without the
graphics (box and cross)... fair enough I thought, I need to display
the email before I print it to ensure that the graphics get embedded,
and then print it and close it again... this doesn't work? I am
getting an error about the email still loading try again later? How
can I get around this since I have to display the message to be able
to print the graphics. I obviously get a new inspector on displaying
the message but can't find anywhere to put the printout method that
makes any difference?????

I hope that I am missing something really obvious here, and someone
can help me. Any points, tips, tricks, advice greatly appreciated :)

The following is a code sample of the printing bit...

Private Sub colSentItems_ItemAdd(ByVal item As Object)

Set oMailItem = item
Set utils = CreateObject("Redemption.MAPIUtils")

CustomField = utils.HrGetOneProp(oMailItem.MAPIOBJECT, PrCustomTag)

If CustomField = "Print Attachments" Then
oMailItem.Display 'this creates a new inspector
item.PrintOut
oMailItem.Close (olSave)

End If

End Sub



Cheers

Kristy
 
K

Ken Slovak - [MVP - Outlook]

Does it help if you add a DoEvents statement after you open the new
Inspector or if you only print after a boolean flag is set in the
Inspector.Activate event?
 
K

Kristy

Hi Ken

Thanks for the ideas. I tried a doevents statement after opening the
message and before printing...

X = Timer()
Do While X + 10 > Timer()

DoEvents

Loop

.... but the HTML message still wouldn't complete loading. How would I
set up a boolean flag on the Inspector.Activate event to test that the
message was loaded ie. what property confirms that loading is
complete? Again I guess I'd need to use a timer loop? It seems
strange that with doevents and a 10 second loop that the message
doesn't load. I am testing this on very small messages that only take
a split second to load manually. Also if I open them programmatically
and do other things to them they are fine, it seems to be the
execution of the Printout method that throws everything into a tail
spin!

Thanks again

Kris
 
K

Ken Slovak - [MVP - Outlook]

The Boolean flag would be a global for example. It would be set in an
Inspector.Activate event handler. So if you have an Inspector wrapper
collection or are just handling NewInspector you would have an Inspector
declared WithEvents which would enable you to handle the Activate event.

However, a 10 second timer loop that doesn't work seems like overkill and
I'd begin to suspect something other than just a time delay. Something else
may be preventing the print method from working. Does it work if you
explicitly do something with the item in the Inspector
(Inspector.CurrentItem) like reading HTMLBody into a string variable or use
the Display method or something like that.

I almost never use Outlook's built-in printing methods. They are too limited
and don't let you select where to print. I usually use a Word template and
populate that in code or an Excel worksheet I can fill in using code and use
Word's or Excel's printing methods which are far more flexible.
 
K

Kristy

Hi

I'm back to looking at this again, unfortunately I can't escape it and
I am stumped as to why it doesn't work.

Thanks Ken for all your advice it is very helpful, and I agree that
printing via Word is far superior, I do it with most of my forms
however for this specific project (for reasons too numerous to mention
here) I need to be able to...

a) Print an HTML Mail Message programmatically from Outlook to the
default printer (I can't use Word or Excel for this one)
b) The Message must be displayed when it is printed as it has embedded
graphics that need to load (so they can print too).
c) The message also needs to be opened programmatically using
GetItemFromID.... and this seems to be what is causing the problem.
If I don't disply the item then it WILL print without error, but as
mentioned earlier I need to display the message first to be able to
print the embedded graphics.

Can someone please try the code below (shortened and simplified - no
graphics, for testing purposes) and see if you have the same problem,
and if you know why it happens.

Test: Create and open an HTML message, needs to be saved or sent to
yourself to get EntryID on current item...

Set objItem = Outlook.Application.ActiveInspector.CurrentItem
EID = objItem.EntryID
objItem.Close (olSave)
Set objItem = Nothing

Set objNS = Application.GetNamespace("MAPI")
Set objMailItem = objNS.GetItemFromID(EID)
objMailItem.Display
objMailItem.PrintOut

I get a message saying that it can't print because the message is
still loading, if I click OK to this message, go back into my VB6
project in debug mode and run objMailItem.Printout for a second time
then it will print, obviously clicking OK to the error message
releases it or something???

As mentioned in previous posts I have tried a number of time delay
loops and a boolean flag (as suggested by Ken) but nothing has worked
so far.

Any ideas... PLEEEEASSSSSE, I know I've already had great suggestions
on alternative methods of printing but in this case it has to be done
via Outlook and the message must be displayed :-(

Kristy
 
K

Ken Slovak - [MVP - Outlook]

Your code works here, I just tested it but I added StoreID (from
objItem.Parent.StoreID) to the GetItemFromID call.

I tested using the Outlook editor. Are you using Word as the email editor?
That would make a big difference. Also what could make a difference is the
Outlook version. If you are using Word as the email editor see if you can
get the Word document object (If objInspector.IsWordMail Then Set objWordDoc
= objInspector.WordEditor). If that works for you then just print using the
Word methods.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top