how to print

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

Hello, I have a C++ program and need to print some data which looks like an
Outlook message: mailbox title name, a line, From field, Sent, To, one
custom field, Subject, and body text (maybe multiple pages). Is it possible
to use Outlook itself to print such a message via office automation, insert
a custom field which has to print too and print it somehow? It must support
Outlook XP and Outlook 2003. Is this possible or do I have to program a
printing routine myself?

cross-post to
- microsoft.public.outlook.program_vba
- microsoft.public.outlook.program_addins
- microsoft.public.outlook.printing
(I'm not sure which is the right group for office automation.)
 
Yes, each Outlook object (MailItem, ContactItem, etc.) has a PrintOut method. Custom fields are automatically included, in alphabetical order. You can add them with the MailItem.UserProperties.add method.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Thanks, Sue.
In the meantime I've also found out how to do this in VB6. Here's my code:
(declarations etc. omitted)
Set o = CreateObject("Outlook.Application")
Set it = o.CreateItem(olMailItem)
it.To = "Bauersachs Eric"
it.ItemProperties.Add("Von", olText) = "Müller Benjamin"
it.ItemProperties.Add("Gesendet", olDateTime) = #12/19/2006 9:40:00 AM#
it.Subject = "RE: Texte deutsch"
it.ItemProperties.Add("Mailtyp", olText) = "3er Meldung"
it.body = "Bodytext"
it.PrintOut
This works and doesn't show up any security alerts.
Currently I'm struggling with the IDispatch interface when converting into
C++. But that's another question and doesn't belong to here.
Thanks again. Question solved.
Eric
 
Follow-up questions:
- I've used MailItem.ItemProperties.Add() instead of
MailItem.UserProperties.Add(). What is the difference? (both works and
prints)
- Now I've got another problem. When I add a property with the name
"Gesendet" and type olText using ItemProperties I get the run-time error
9ac20009 "Method 'Add' of object 'ItemProperties' failed". When I use
UserProperties instead I get the run-time error 9ac20009 "A custom field
with this name but a different data type already exists. Enter a different
name."

If I change the data type to olDateTime it works. But the UserProperties
collection is empty before this call. And the ItemProperties collection
contains 81 entries, but none with this name.

The name "Gesendet" is german for "Sent", but I've used other property names
like "Von" (german for "From") etc. without problems. And I'm using an
english Outlook, an english Exchange server and an english Windows Server
2003. What could be the problem here? I don't understand why there should be
existing properties in a new empty message.

Eric
 
- I've used MailItem.ItemProperties.Add() instead of
MailItem.UserProperties.Add(). What is the difference? (both works and
prints)

You can use either to add a custom property. It should make no difference.
- Now I've got another problem. When I add a property with the name
"Gesendet" and type olText using ItemProperties I get the run-time error
9ac20009 "Method 'Add' of object 'ItemProperties' failed". When I use
UserProperties instead I get the run-time error 9ac20009 "A custom field
with this name but a different data type already exists. Enter a different
name."

If I change the data type to olDateTime it works. But the UserProperties
collection is empty before this call. And the ItemProperties collection
contains 81 entries, but none with this name.

That suggests that the field already exists in the parent folder of the item to which you're adding the properties with the other name. Did you look there? Did you try setting the third-parameter of the Add method to False?
The name "Gesendet" is german for "Sent", but I've used other property names
like "Von" (german for "From") etc. without problems. And I'm using an
english Outlook, an english Exchange server and an english Windows Server
2003. What could be the problem here? I don't understand why there should be
existing properties in a new empty message.

The existing properties very likely are not those in the item. Adding a new property to an item by default also adds it to the parent folder of the item. If you added Gesendet earlier as a date/time property, you can't add it again as a text property.

Also, the way Outlook handles localized names for built-in fields is a very poorly documented area. That could be a factor as well.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top