Link to home
Start Free TrialLog in
Avatar of centralmike
centralmike

asked on

MAIL MERGE IN ACCESS 2007/MS WORD 2007

Is there anyway to get ird of the pop-up error message in the mail merge process from access to word? Error "Opening this document will run the following SQL command:  Select * from [table].
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

You can edit the registry to suppress that security message. The details are here:
http://support.microsoft.com/kb/825765
Avatar of centralmike
centralmike

ASKER

I am sorry we are large company.  We are not allowed to change the registry settings.  Is there anyway through code to eliminate this message from popping up?
The only other way would be to save the main document as a 'Normal Word Document', and to re-establish it as a merge document and to reconnect the record source each time that it is opened.

This could be done in VBA code (if you allowed to use it)
If possible can you send me an example of that process.  Changing the "Main Document" into a "Normal Document" through code.  When the mail merge process ends I would word to return to its normal process being the "Main Dcoument".
Here is a sample.
Sub SetUpDocumentAndMerge(docMain As Document)

    With docMain.MailMerge
        .MainDocumentType = wdFormLetters
        .Destination = wdSendToNewDocument
        .OpenDataSource Name:="X:\MyDatabases\MyFile.mdb", _
            SQLStatement:="SELECT * FROM `MyTable`"
        .Execute
    End With
    docMain.Close wdDoNotSaveChanges 'thus saved document remains a non-merge document
    
End Sub

Open in new window

Graham, I going to send you a copy of my module if you can add the line of code that will allow me to close the document without saving.
---------------------------------------------------------------------------------------------------------------------------------------------
Function MergeIt()

DoCmd.SetWarnings False
   Dim objWord As Word.Document
   Set objWord = GetObject("X:\Special Risk\miketesting\DEVELOPMENT\merge.docx", "Word.Document")


 
   objWord.Application.Visible = True
    objWord.MailMerge.OpenDataSource _
      Name:="X:\Special Risk\miketesting\DEVELOPMENT\SELECTIONPATHCHOOSEN.ACCDB", _
      LinkToSource:=True, _
      Connection:="TABLE TABLE1", _
      SQLStatement:="SELECT * FROM [TABLE1]"
   ' Execute the mail merge.
   
   objWord.MailMerge.Destination = wdSendToNewDocument
 ' aDoc.MailMerge.MainDocumentType = wdNotAMergeDocument

   objWord.MailMerge.Execute



objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
'DoCmd.SetWarnings True



End Function
You don't have a separate object variable for the Word application, so you need to keep the main document open until the printing has been done:
Function MergeIt()

DoCmd.SetWarnings False
   Dim objWord As Word.Document
   Set objWord = GetObject("X:\Special Risk\miketesting\DEVELOPMENT\merge.docx", "Word.Document")
 
   objWord.Application.Visible = True
    objWord.MailMerge.OpenDataSource _
      Name:="X:\Special Risk\miketesting\DEVELOPMENT\SELECTIONPATHCHOOSEN.ACCDB", _
      LinkToSource:=True, _
      Connection:="TABLE TABLE1", _
      SQLStatement:="SELECT * FROM [TABLE1]"
   ' Execute the mail merge.
   
   objWord.MailMerge.Destination = wdSendToNewDocument
 ' aDoc.MailMerge.MainDocumentType = wdNotAMergeDocument

   objWord.MailMerge.Execute

objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
'DoCmd.SetWarnings True
objWord.Close wdDoNotSaveChanges

End Function  

Open in new window

Good Morning Graham, I ran the module above and still receive the following sql error prompt.   Is there something else I am missing?
The code doesn't actually remove merge status and link.

Open the document manually, set to a Normal Word Document and save it. Next time that it opens, it will be as such.

Our code converts it to a main document, uses it and then closes it without saving.
Just one last question Graham.  After the merge process ends word remains open.  I would close it after the last document prints.  I tried the following statement: objWord.Application.Quit an received an error message "462"
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Now I am receiving a runtime error 13 on the following line.

  Set objWord = objWordApp.Documents.Open("X:\Special Risk\miketesting\DEVELOPMENT\merge.docx", "Word.Document")
Oops. I couldn't actually test the code because it referred to your folders. I changed your GetObject line into the Open code and failed to remove the ' , "Word.Document"' bit.

it should read:
 Set objWord = objWordApp.Documents.Open("X:\Special Risk\miketesting\DEVELOPMENT\merge.docx")
Thanks for all the help Graham.  Sorry for the delay I had to leave town.