Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / January 2005

Tip: Looking for answers? Try searching our database.

Controlling a Word Mail Merge (from Access)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Derek Wittman - 14 Jan 2005 21:07 GMT
Good afternoon,
I am working on controlling a Mail Merge from within MS Access using the
Word references.  I have my main document and my datasource already linked to
it.  What I cannot figure out is how to do the equivalent of Merging to a New
Document by way of the VBA code.  

I want to merge to the new document, then save the document, then print or
email (depending on what the user selects).

Any and all help is greatly appreciated!  Thank you!

Derek

My code is:

Private Sub cmdSubmit_Click()
Dim MSwordApp As word.Application
Dim MSwordDoc As word.Document
Dim strwordfilename As String
Dim savewordfilename As String
Dim selectme As Integer

DoCmd.RunSQL "Delete * from tblShortFormData"

Select Case txtRemaining

   Case Is > 0.01, Is < -0.01

   MsgBox "The total percentage MUST equal 100%.  Please use the
'Remaining' field to check your math.", vbOKOnly, "Check your calcuations:"

Case Else
   DoCmd.RunSQL "INSERT INTO tblShortFormData ([Store#], ProjectID,
ContractDate, Vendorname, Price, CompletionDate, WorkDesc, ProgPC1, ProgPC2,
ProgPC3, ProgPC4, ProgPC5, ProgPC6, ProgPC7, ProgPC8, Term1, Term2, Term3,
Term4, Term5, Term6, Term7, Term8) SELECT forms!frmShortForm.cboDCNumber,
Forms!frmShortForm.txtProjectNo, date(), forms!frmShortForm.txtVendor,
forms!frmShortForm.txtPrice, forms!frmShortForm.txtDone,
forms!frmShortForm.txtScope, forms!frmShortForm.txtPC1,
forms!frmShortForm.txtPC2, forms!frmShortForm.txtPC3,
forms!frmShortForm.txtPC4, forms!frmShortForm.txtPC5,
forms!frmShortForm.txtPC6, forms!frmShortForm.txtPC7,
forms!frmShortForm.txtPC8, forms!frmShortForm.txtTerm1,
forms!frmShortForm.txtTerm2, forms!frmShortForm.txtTerm3,
forms!frmShortForm.txtTerm4, forms!frmShortForm.txtTerm5,
forms!frmShortForm.txtTerm6, forms!frmShortForm.txtTerm7,
forms!frmShortForm.txtTerm8"

Set MSwordApp = CreateObject("word.application")

MSwordApp.Visible = True

strwordfilename =
"v:\distcntr\dcdesign\projmgmt\Contract\Short_Forms\Short_FormB_Unprotected.doc"

Set MSwordDoc = MSwordApp.Documents.Open(strwordfilename)

savewordfilename = "v:\distcntr\dcdesign\projmgmt\contract\Short_Forms\" &
Forms!frmShortForm.cboDCNumber & Forms!frmShortForm.txtVendor & ".doc"

MSwordApp.ActiveDocument.MailMerge.Destination = wdSendToNewDocument

MSwordDoc.SaveAs (savewordfilename)

selectme = MsgBox("Do you want to print or email the Short Form Contract?
YES to Print and NO to email", vbYesNo, "YES to Print or NO to email")

Select Case selectme
Case 6
   MSwordDoc.PrintOut , , , , , , , , , , , True
Case 7
   MSwordApp.ActiveDocument.SendMail
End Select
MSwordDoc.Close
MSwordApp.Quit
Set MSwordDoc = Nothing
Set MSwordApp = Nothing
DoCmd.SelectObject acForm, "frmShortForm"
DoCmd.Close
End Select
End Sub
Joe Smith - 17 Jan 2005 05:43 GMT
According to the MSDN, right after thie following line:

MSwordApp.ActiveDocument.MailMerge.Destination = wdSendToNewDocument

you then need

MSwordApp.ActiveDocument.MailMerge.Execute

I guess that executes the mail merge.

Here's the link I used as reference

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/office97/html/o
utput/F1/D4/S5A9DB.asp


Hope that helps

Steve

> Good afternoon,
> I am working on controlling a Mail Merge from within MS Access using the
[quoted text clipped - 81 lines]
> End Select
> End Sub
Derek Wittman - 17 Jan 2005 13:11 GMT
Steve/Joe,
Yes, it did help.  However, I'm on the next 'step' and in a bit of a jam.  
My .execute merges the form into a document called "Form Letters1".  Well, I
want to close my main document (the one that executes the merge) and save the
new "Form Letters1" as savefilename.  Since I'm doing this (as you can tell)
over a network, might it be quicker to close the document and change the
filename using the filesystem code?  Or should I do the saveas in the code
below?

Thanks!
Derek

> According to the MSDN, right after thie following line:
>
[quoted text clipped - 13 lines]
>
> Steve

> > Good afternoon,
> > I am working on controlling a Mail Merge from within MS Access using the
[quoted text clipped - 81 lines]
> > End Select
> > End Sub
 
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



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