Group,
I have created a mail merge process within MS ACCESS using VBA, but my problem is the message that appears at each merge process "Opening this document will run the following SQL command:" etc, etc.... I have found that I could possibly edit the registry on each machine to prevent this, but only will resort to this if I cannot control this within VBA.
The process, the MS WORD document is not linked to the datasource:
FIRST TIME through the process:
enter data
"merge" from within MS ACCESS
all works - no message.
Then I repeat the process,
enter data
and now the message appears.
After the first time of the VBA process, the MSWORD document now includes the link. When I open the document itself, I will get the message "opening this document will run, etc, etc....."
so within the vba code, is it possible to "unlink" the datasource after the merge process and before I close my document. Even though I am closing the document with "do not save changes" - the link is saved within the original document, thus causing the SQL message.
my vba code:
Private Sub btnMERGE_Click()
Dim objWord As Word.Document
Set objWord = GetObject("c:\user\mydocuments\mergedoc.docx")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Users\usrprofile\Documents\msaccessname.accdb", _
linktosource:=True, _
Connection:="TABLE tablename", _
SQLStatement:="SELECT * FROM [tablename]"
' Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
objWord.Close (savechanges = wdDoNotSaveChanges)
End Sub
Any suggestions would be appreciated!
I have created a mail merge process within MS ACCESS using VBA, but my problem is the message that appears at each merge process "Opening this document will run the following SQL command:" etc, etc.... I have found that I could possibly edit the registry on each machine to prevent this, but only will resort to this if I cannot control this within VBA.
The process, the MS WORD document is not linked to the datasource:
FIRST TIME through the process:
enter data
"merge" from within MS ACCESS
all works - no message.
Then I repeat the process,
enter data
and now the message appears.
After the first time of the VBA process, the MSWORD document now includes the link. When I open the document itself, I will get the message "opening this document will run, etc, etc....."
so within the vba code, is it possible to "unlink" the datasource after the merge process and before I close my document. Even though I am closing the document with "do not save changes" - the link is saved within the original document, thus causing the SQL message.
my vba code:
Private Sub btnMERGE_Click()
Dim objWord As Word.Document
Set objWord = GetObject("c:\user\mydocuments\mergedoc.docx")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Users\usrprofile\Documents\msaccessname.accdb", _
linktosource:=True, _
Connection:="TABLE tablename", _
SQLStatement:="SELECT * FROM [tablename]"
' Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
objWord.Close (savechanges = wdDoNotSaveChanges)
End Sub
Any suggestions would be appreciated!