Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macros and mail merges--control issue 1

Status
Not open for further replies.

jgarnick

Programmer
Feb 16, 2000
189
US
I have a macro that creates a table, then it starts a batch file running that opens up Word and starts a Word macro running which merges a Word document with the Access table.&nbsp;&nbsp;That all works fine.&nbsp;&nbsp;When the user closes Word, they are back in Access.&nbsp;&nbsp;I need to put a question in to ask the user if it is ok to run an update query once they are back in Access.&nbsp;&nbsp;My problem has been that the msgbox question whether in code or in the macro holds up the process waiting for an answer--in other words it does not wait until the user is done in Word.<br><br>Where is the best place to put such a question and how do I make it not appear until the user closes Word?<br><br>Thanks! <p>jgarnick<br><a href=mailto:jgarnick@aol.com>jgarnick@aol.com</a><br><a href= > </a><br>
 
I would be happy to help you with this problem. Are you willing to rethink how you are doing this merge? I have an app that creates a record in a table and then launches Word, and rather than having a macro in Word do a merge I programmatically insert the field info into bookmarked locations in Word and shutdown Word from Access. Then you can have anything else you want happen.&nbsp;&nbsp;You don't have to rely on Word firing the Word macro. The user never even sees Word.<br><br><br>Sub WordBookmark(ByVal worddoc As String)&nbsp;&nbsp;<br><br>'pass the doc name to merged to<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Dim dbsa As Database<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim rst As Recordset<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim objWord As Word.Application<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim objdoc As Word.Document<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim fld As field<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim bkmark As bookmark<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Set dbsa = CurrentDb()<br>&nbsp;&nbsp;&nbsp;&nbsp;Set rst = dbsa.OpenRecordset(&quot;tblTempWordMerge&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;worddoc = &quot;yournetworklocation&quot; & worddoc<br>&nbsp;&nbsp;&nbsp;&nbsp;Set objWord = New Word.Application<br>&nbsp;&nbsp;&nbsp;&nbsp;Set objdoc = objWord.Documents.Open(worddoc)<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'loop through fields in export table and send data <br>&nbsp;&nbsp;&nbsp;&nbsp;'to corresponding bookmark in word doc<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'this is a sample of merging info from one field <br>&nbsp;&nbsp;&nbsp;&nbsp;'into one bookmark<br><br>&nbsp;&nbsp;&nbsp;&nbsp;objdoc.Bookmarks(&quot;yourbookmarkname&quot;).Select<br>&nbsp;&nbsp;&nbsp;&nbsp;objWord.Selection.Text = rst!field<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;objWord.PrintOut (False)<br>&nbsp;&nbsp;&nbsp;&nbsp;objdoc.Close wdDoNotSaveChanges<br>&nbsp;&nbsp;&nbsp;&nbsp;objWord.Quit<br>&nbsp;&nbsp;&nbsp;&nbsp;rst.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;dbsa.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;Set objdoc = Nothing<br>&nbsp;&nbsp;&nbsp;&nbsp;Set objWord = Nothing<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>End Sub<br><br>Let me know if I can help
 
Thanks for your help!&nbsp;&nbsp;However, in my situation, the user needs to be out in Word.&nbsp;&nbsp;It's a bunch of form letters and some need to be personalized etc.&nbsp;&nbsp;Plus there are some timing issues as to when to send them to the printer etc.<br><br>I may be able to use your help for another future purpose--thanks! <p>jgarnick<br><a href=mailto:jgarnick@aol.com>jgarnick@aol.com</a><br><a href= > </a><br>
 
By default, Access asks the user if it is OK before running an Update query. Just curious why you need to do this manually?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top