Hey,
Here is some code that we used to create a MHT file of the form and send it via email. Note that your form will need to be fully trusted.
In the button code put the following:
Dim oFormNum, oFormName, sMHT
Dim sTo, sCC, sBCC, sSubj, sBody
'grab the form number and title of current form
Set oFormNum = XDocument.DOM.selectSingleNode("//my:FORMINFO/my:FormNumber")
Set oFormName = XDocument.DOM.selectSingleNode("//my:FORMINFO/my:FormTitle")
'create the MHT file 1st
sMHT = CreateMHT(oFormNum.Text)
'create the email envelope
sTo = ""
sCC = ""
sBCC = ""
sSubj = oFormNum.text & " - " & oFormName.text
sBody = "message for the body of the email"
CreateMailMsg sTo, sCC, sBCC, sSubj, sBody, sMHT
Add the following subroutine and function to your script file:
Function CreateMHT(sFormNum)
'purpose to create a MHT web file of the form with its data for the user
'date 4/13/2006
'revised
Dim wshShell,oFileSys, filePath, sFormFile, myDocs, sFile, sDate
'unique name for file
sDate = Year(Now) & Month(Now) & Day(Now) & "_" & Hour(Now) & Minute(Now) & Second(Now)
sFile = sFormNum & "_" & sDate & ".mht"
Set wshShell = Createobject("WScript.Shell")
'path to user's data - assumes there is a Forms folder under My Documents
myDocs = wshShell.SpecialFolders("MyDocuments")
filePath = myDocs & "\Forms\"
'check if path file exists
Set oFileSys = CreateObject("Scripting.FileSystemObject")
If oFileSys.FolderExists(filePath) Then
sFormFile = filePath & sFile
Else
sFormFile = myDocs & sFile
End if
'check to see if the file exists - if it does, overwrite it
If oFileSys.FileExists(sFormFile) Then
oFileSys.DeleteFile sFormFile, True
end if
'create the mht file - needs digital certificate to do this
XDocument.View.Export sFormFile, "MHT"
CreateMHT = sFormFile
End Function
Sub CreateMailMsg(sTo, sCC, sBCC, sSubj, sBody, sAttachFile)
'purpose creates an outlook message and attaches the MHT file created above
'date 04/19/2006
Dim objOlApp
Dim objItm
Set objOlApp = CreateObject("Outlook.Application")
Set objItm = objOlApp.CreateItem(olMailItem)
With objItm
.To = sTo
.CC = sCC
.BCC = sBCC
.Subject = sSubj
.Body = sBody
.Attachments.Add sAttachFile
.Display
End With
End Sub
Hope that helps,
MB