Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 20th, 2005, 12:59 PM
Registered User
 
Join Date: Apr 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Kevinsharrison
Default Merge to word from excel

I am trying to do a mail merge from access and I have a couple of problems. I am creating a excel file and mergeing off of that. But everytime I save the excel file it prompts if the user wants to overwrite the file. I would like to get rid of that and I have tried:

DoCmd.SetWarnings False
objExcel.ActiveWorkbook.Close True, "c:\merge.xls"
DoCmd.SetWarnings True

But that doesn't do it.

Then when I do the merge:

DoCmd.SetWarnings False
With objword
.Visible = True
.Documents.Open "C:\merge.doc", , False
.ActiveDocument.Mailmerge.OpenDataSource "C:\merge.xls", , , False, True
.ActiveDocument.Mailmerge.Destination = wdSendToNewDocument
.ActiveDocument.Mailmerge.Execute
End With
DoCmd.SetWarnings True

but it prompts the user what sheet to do the merge off of. I would like to get rid of that but as you see I have tried the setwarnings to false with no luck. I am working with access 2003 with a 2000 file and I don't know if it is something 2000+. I know that it used to do it in 97 and it is not working here.


If anyone has any suggestions for me it would be a lot of help. I am a newbee.

Thanks
Kevin
 
Old April 26th, 2005, 07:40 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

The file overwrite warning probably comes from Excel. Before the close try:

objExcel.DisplayAlerts = False

I don't have time to find out, but I think your merge needs something like:

.ActiveDocument.Mailmerge.OpenDataSource "C:\merge.xls![Sheet1]",,,false,true

In other words, specify the sheet in the data source. Another option could be to delete the extra worksheets in Excel before you close the file. I think if Excel has only one worksheet it knows where to go for the data.

Of course you might try skipping the whole output to Excel and use a query in Access as your data source. Of course that depends on whether your Excel output is more than just a simple query. Not sure the syntax for that but it might be as simple as:

.OpenDataSource CodeDB().Name & "![queryname]" ???

You could record a macro in Word to get all of the proper commands to copy (and update as appropriate) in your Access code. That's usually the way I figure out what I need.


Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org





Similar Threads
Thread Thread Starter Forum Replies Last Post
Word - Merge print/save mat41 Classic ASP Professional 0 October 26th, 2008 06:12 PM
Programatic word merge fizzerchris Access VBA 3 September 20th, 2007 09:12 PM
Merge Word with catalogue option chichiboof VBScript 0 October 17th, 2006 06:06 AM
Mail Merge with MS Word bezaman Classic ASP Basics 1 October 6th, 2005 04:13 PM
Access OLE Merge to Word GregoryHu Access VBA 5 May 7th, 2004 10:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.