Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Printing / February 2007

Tip: Looking for answers? Try searching our database.

how to print

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eric - 22 Jan 2007 11:09 GMT
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.)
Sue Mosher [MVP-Outlook] - 22 Jan 2007 13:16 GMT
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.
Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx
 

> 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
[quoted text clipped - 9 lines]
> - microsoft.public.outlook.printing
> (I'm not sure which is the right group for office automation.)
Eric - 22 Jan 2007 15:11 GMT
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
Eric - 22 Jan 2007 23:39 GMT
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
Sue Mosher [MVP-Outlook] - 01 Feb 2007 02:20 GMT
> - 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
[quoted text clipped - 6 lines]
> 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.

Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx
 

>
> Eric
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.