Create an instance of Outlook from within InfoPath

H

Humphrey

I have been charged with writing some simple code to
1. Print a form to PDF on close,
2. take the thus created PDF file and attach it to an email message,
3. send the message,
4. delete the PDF file,
5. complete the close

Now I've run out of puff at line 2. How do I do this using the Visual Basic
language editor. I've done this thousands of times using VBA in Access but
the editor doesn't seem to recognise the Outlook reference once it is set up.

Can someone please guide a weary traveller?

H
 
G

Greg Collins

While it sounds like you already have print to PDF working (from your
comment about getting stuck at line 2), Please note a few things (if not for
your benefit, for the benefit of others reading this):

1. There is no OnClose event that you can capture.
2. Each view (or print view) can only have one printer associated with it.
3. Because of InfoPath limitations, you cannot in code switch to another
view to print it (the problem is that the view is not generated until
control is given back to InfoPath from the code, so you get the old view).
4. If you do make a view switch via code, you can't switch back. InfoPath
only allows for a single view switch per call to code.
5. Printing via code requires your form top be full trust.

Assuming you got the print to PDF working, you should be able to write some
Outlook automation to create a new email and attach the PDF and send. You
could do this using an email submit adapter as well. Deleting the PDF via
code should be straight forward (assuming you were able to specify the
printout location and filename). Closing the form is straight forward.
 
H

Humphrey

Thanks Greg,

One "advantage" if you can call it that of not working in an office is
that I have the PDF printer set up as the default, so coding the form to
print to the default printer is no biggie.
The problem is that the Outlook automation I'm used to is VBA from Access
and Excel. I've tried copy paste across to InfoPath but it will not work.
The programming in VSTO is sufficiently dfferent that I cannot get my
original code to work. Could you point me in the direction of sample code.
Everything I've read about email from infopath is about sending the current
form, I couldn't find anything about sending other attachments.
Do I have access to the FileSystemObject in this environment?

H
 

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