Custom Form Code

J

Joel Allen

Hello,

I have a custom form that auto populates a Word template. I do this to
populate the subject field and it works:

objDoc.MailEnvelope.Item.Subject = "Test"

I'm trying to attach to it and it's not working. I'm trying this:

objDoc.MailEnvelope.Item.Attachments = "C:\Test.doc"

and this:

objDoc.MailEnvelope.Item.Attachments.Add = "C:\Test.doc"

and it's not working.

Any help is much appriciated. Thanks,
Joel
 
J

Joel Allen

Yes, thanks for your help.

Sub CommandButton1_Click()
Dim objDoc
On Error Resume Next
Set objDoc =
GetWordDoc("\\tgps8\drawing$\Jobs\Task_Templates\Letter-Shop Drawing
Xmit.dot")
Call FillFields1(objDoc)
objDoc.Application.Options.PrintBackground = True
'objDoc.PrintOut
'objDoc.Close wdDoNotSaveChanges
objDoc.MailEnvelope.Item.To = Item.UserProperties("ContactEmail")
objDoc.MailEnvelope.Item.Attachments = "C:\Test.doc"
objDoc.MailEnvelope.Item.Subject = "#"+Item.UserProperties("JobNumber")+"
"+Item.UserProperties("JobName")+" - PO# "+Item.UserProperties("CustomerPO")
Call RestoreWord
Set objDoc = Nothing
End Sub



Sub FillFields1(objDoc)

On Error Resume Next
Dim colFields
Set colFields = objDoc.FormFields
' colFields("RequestDate").Result = Item.LastModificationTime
colFields("CompanyName").Result = _
Item.UserProperties("CompanyName")
colFields("MAStreet").Result = _
Item.UserProperties("MAStreet")
colFields("MACity").Result = _
Item.UserProperties("MACity")
colFields("MAState").Result = _
Item.UserProperties("MAState")
colFields("MAZip").Result = _
Item.UserProperties("MAZip")
colFields("MACountry").Result = _
Item.UserProperties("MACountry")
colFields("ContactName").Result = _
Item.UserProperties("ContactName")
colFields("ContactNameLast").Result = _
Item.UserProperties("ContactNameLast")
colFields("ContactName2").Result = _
Item.UserProperties("ContactName")
colFields("JobNumber").Result = _
Item.UserProperties("JobNumber")
colFields("JobName").Result = _
Item.UserProperties("JobName")
colFields("CustomerPO").Result = _
Item.UserProperties("CustomerPO")
colFields("TwentyFivePercent").Result = _
Item.UserProperties("TwentyFivePercent")
colFields("TwentyFivePercentRep").Result = _
Item.UserProperties("TwentyFivePercent")

colFields("TwentyFivePercent3").Result = _
Item.UserProperties("TwentyFivePercent")

colFields("TwentyFivePercent4").Result = _
Item.UserProperties("TwentyFivePercent")

colFields("TwentyFivePercent5").Result = _
Item.UserProperties("TwentyFivePercent")

colFields("ContactPhoneNumber").Result = _
Item.UserProperties("ContactPhoneNumber")
colFields("ContactFaxNumber").Result = _
Item.UserProperties("ContactFaxNumber")

Call SetPMValues
colFields("PMPosition").Result = PMPosition
colFields("PM").Result = PM
colFields("PM2").Result = PM2
colFields("PMFAX").Result = PMFAX
colFields("PMFAX2").Result = PMFAX2
colFields("PMFAX3").Result = PMFAX3
colFields("PMEXT").Result = PMEXT
colFields("PMEXT2").Result = PMEXT2
colFields("PMEMAIL").Result = PMEMAIL

'objDoc.Bookmarks("Details").Range.InsertAfter Item.Body
Set colFields = Nothing
End Sub





Private Function GetWordDoc(strTemplatePath)
Dim objWord
On Error Resume Next
m_blnWeOpenedWord = False
Set objWord = GetObject(, "Word.Application")
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
m_blnWeOpenedWord = True
End If
m_blnWordPrintBackground = _
objWord.Options.PrintBackground
If strTemplatePath = "" Then
strTemplatePath = "\\tgps8\drawing$\Jobs\Task_Templates\Normal.dot"
End If
Set GetWordDoc = objWord.Documents.Add(strTemplatePath)
Set objWord = Nothing
End Function






Sub RestoreWord()
Dim objWord
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
objWord.Options.PrintBackground = _
m_blnWordPrintBackground
If m_blnWeOpenedWord Then
objWord.Quit
Else
objWord.Visible = True
End If
Set objWord = Nothing
End Sub
 
J

Joel Allen

Thanks Eric, that worked!

Eric Legault said:
I neglected to mention that Attachments.Add("C:\MyFolder\MyFile.txt") is
the
proper way to add an attachment.

Try removing all the On Error Resume Next statements and see if you get a
specific error at a specific point.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/
 

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

Similar Threads


Top