Link to home
Start Free TrialLog in
Avatar of Sheils
SheilsFlag for Australia

asked on

Error when mail merging using Albert kallal's code while a word document is open

Hi

I have been using Albert Kallal mail merge code for a while without any problem. However, I have recently found a problem that I hope you expert can help solve.

When you try to fun the code to conduct a mail merge while a word document that was not opened by the code in access is already opened you get message saying:

This document will run the following SQL command:

Select * from C:\docume~1\................\temp\merge.888.

Data from your database will be placed in the document. Do you want to continue.


Clicking yes proceeds with the mail merge. Is there a way to make the code proceed without the message even when there is another open word document.

Albert Kallal db is in the attached zip folder
WordMerge2008.zip
Avatar of Sheils
Sheils
Flag of Australia image

ASKER

I believe that I've found a fix. When I change the following:

On Error GoTo CreateWordApp
   
   If bolPrint = True Then
      ' we printing a document, so lets launch a seperate copy of word
      ' as not interfere with the the user's current open copy of word
     
      Set wordApp = GetObject("Word.Application")
   Else
      Set wordApp = GetObject(, "Word.Application")
   End IfOn Error GoTo CreateWordApp
   

TO

   If bolPrint = True Then
      ' we printing a document, so lets launch a seperate copy of word
      ' as not interfere with the the user's current open copy of word
     
      Set wordApp = GetObject("Word.Application")
   Else
      Set wordApp = GetObject("Word.Application") 'delete the comma before "Word.Application"
   End If

The word document opens without the message.

Please advice if such change will create other forseeable errors



Avatar of GrahamSkan
I dont understand the code that you have posted, or the fix.

You do the same thing in the True and the False (Else) parts of the If block.


Also the message that you report is not an error, but is a security warning. This Microsoft article tells you how to modify the registry to remove the message.

http://support.microsoft.com/kb/825765
Avatar of Sheils

ASKER

Graham

In the original code there was a comma in from of "word.application"  in the Else part of the If block. The idea was that if a word document was already opened the code will open the new document in the same instance as the opened document. By removing the comma the new document opens in a new window no matter what. In effect I could just remove the If block and replace it by

 Set wordApp = GetObject("Word.Application")


To use the work around in the link you provided above, I'd have to change the register of every computer that have to us this database since it is on a network. So that's not practical.
Interesting. On my system it raises a run time error (800401e4)-  Automation error - Invalid syntax.
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
Yes, I've just checked the code in the database that you posted.

Actually, I don't think that would get round the security message. There is as OpenDatasourc line in the code, so perhaps the perhaps the document is not a mail merge document when it is opened, but the code turns it into one.