Hi Tim,
In order to get the functionality you need, you will need to "automate"
Outlook using the Outlook object model. As such, for this to work you will
need to insure your form is "fully trusted." (If you need more information
on fully trusted forms, let me know and I'll post the links.
In addition, in order to automatically attach the form the user is working
on it will need to first be saved so Outlook can locate it for the
attachment.
Here is some sample code (VBScript) to automate Outlook and automatically
save the form for attachment - this could be called on the click event of a
button:
Dim objOutlook
Dim objOutlookMsg
Dim objOutlookRecip
Dim objOutlookAttach
Dim frmSavePath
'Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0) 'olMailItem
With objOutlookMsg
'Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("(e-mail address removed)")
objOutlookRecip.Type = 1 'olTo
' 'Add the CC recipient(s) to the message.
' Set objOutlookRecip = .Recipients.Add("(e-mail address removed)")
' objOutlookRecip.Type = 2 'olCC
'
' 'Add the BCC recipient(s) to the message.
' Set objOutlookRecip = .Recipients.Add("(e-mail address removed)")
' objOutlookRecip.Type = 3 'olBCC
'Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.body = "This is the body of the message"
' **NOTE: if you want the body of the message to be HTML, then use
'.HTMLbody instead of just .body
.Importance = 2 'High importance
'Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
'Display the message before sending
.display
'If you want to add the form as an attachment, you need to make sure it
is saved
'first and then add that file as an attachment
frmSavePath = "C:\MyForm.XML"
XDocument.SaveAs(frmSavePath)
Set objOutlookAttach = .Attachments.Add(frmSavePath)
End With
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
I hope this helps!
Best regards,
Scott L. Heim
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.