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 / Programming VBA / August 2007

Tip: Looking for answers? Try searching our database.

Custom Form Code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joel Allen - 14 Aug 2007 19:30 GMT
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
Eric Legault [MVP - Outlook] - 14 Aug 2007 21:56 GMT
That's strange, it should work.  Could you show all of your code please?

Signature

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/

> Hello,
>
[quoted text clipped - 15 lines]
> Any help is much appriciated.  Thanks,
> Joel
Joel Allen - 14 Aug 2007 22:06 GMT
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

> That's strange, it should work.  Could you show all of your code please?
>
[quoted text clipped - 17 lines]
>> Any help is much appriciated.  Thanks,
>> Joel
Eric Legault [MVP - Outlook] - 14 Aug 2007 22:38 GMT
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.

Signature

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/

> Yes, thanks for your help.
>
[quoted text clipped - 133 lines]
> >> Any help is much appriciated.  Thanks,
> >> Joel
Joel Allen - 14 Aug 2007 23:23 GMT
Thanks Eric, that worked!

>I neglected to mention that Attachments.Add("C:\MyFolder\MyFile.txt") is
>the
[quoted text clipped - 144 lines]
>> >> Any help is much appriciated.  Thanks,
>> >> Joel
Eric Legault [MVP - Outlook] - 15 Aug 2007 03:20 GMT
Great!  My bad though - I thought you tried that already, but after rereading
your first post I see now it was a syntax error.

Signature

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/

> Thanks Eric, that worked!
>
[quoted text clipped - 146 lines]
> >> >> Any help is much appriciated.  Thanks,
> >> >> Joel
 
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



©2009 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.