Word Automating MailMerge Problem

R

Roplab

Hi Everyone,
I created a macro package for Authomating MailMerge in
MSWord 2003 the program worked fine but the problem that I am having is that
during the mailmerge process a security warning popup( "Openning "D:\MyDB"
This file may not be safe if it contains code that was intended to harm your
computer. Do you want to open this file or cancel the operation) and if I
click open it Brings another popup saying that "You can t make changes to
this database objects in the database the MyDB....Thus Database was create
in an earlier version of microsoft Access.......") and if I deploy the
template to a machine that does not have microsoft Access, I get a Select
Table Windows. I need to deploy this program on machine that does not have
Access.
Below is the code that I am using

Private Sub cmdOK_Click()
On Error GoTo Para_InitError

Dim oWord As Word.Documents
Dim strTable As String
Dim CntStr As String
Dim Sqlstr As String
Dim MyMerge As Word.MailMerge
Dim x As String

'Fn is the filename of the merging template

'Hide active form
Me.Hide
Documents.Open FileName:=Fn, ReadOnly:=True, AddToRecentFiles:=False
strTable = lsbParalegal.Value
CntStr = "TABLE " & strTable
Sqlstr = "SELECT * FROM " & strTable & " WHERE " _
& "(((" & strTable & ".ID)=" _
& lsbFiles.Value & "))"

Set MyMerge = ActiveDocument.MailMerge
With MyMerge
.MainDocumentType = wdFormLetters
.OpenDataSource Name:="D:\MyFolder\MyDB.mdb", Connection:=CntStr,
SQLSTATEMENT:=Sqlstr, _
SubType:=wdMergeSubTypeWord2000, ReadOnly:=True, LinkToSource:=True,
openExclusive:=True

End With

If MyMerge.State = wdMainAndDataSource Then
MyMerge.Application.DisplayAlerts = wdAlertsNone
MyMerge.Destination = wdSendToNewDocument
MyMerge.Application.Visible = True
MyMerge.Execute pause:=False

x = ActiveDocument.Name
Documents(Fn).Close wdDoNotSaveChanges

Documents(x).Activate
Application.ScreenUpdating = True

End If

Err_handler:
Exit Sub
Para_InitError:
MsgBox "Error No: " & Err.Number & "; error message: " & Err.Description
Resume Err_handler
End Sub

Please help!!!!!
-Ralph
 
C

Cindy M -WordMVP-

Hi Roplab,

It looks like you've set up the connection for DDE. DDE *REQUIRES* the Access
application to be installed, as it communicates directly with the loaded
instance of Access to pass the data into Word.

You'd need to change this to either an OLE DB or ODBC connection (my
preference would, under most circumstances, be the latter).
I created a macro package for Authomating MailMerge in
MSWord 2003 the program worked fine but the problem that I am having is that
during the mailmerge process a security warning popup( "Openning "D:\MyDB"
This file may not be safe if it contains code that was intended to harm your
computer. Do you want to open this file or cancel the operation) and if I
click open it Brings another popup saying that "You can t make changes to
this database objects in the database the MyDB....Thus Database was create
in an earlier version of microsoft Access.......") and if I deploy the
template to a machine that does not have microsoft Access, I get a Select
Table Windows. I need to deploy this program on machine that does not have
Access.
Below is the code that I am using

Private Sub cmdOK_Click()
On Error GoTo Para_InitError

Dim oWord As Word.Documents
Dim strTable As String
Dim CntStr As String
Dim Sqlstr As String
Dim MyMerge As Word.MailMerge
Dim x As String

'Fn is the filename of the merging template

'Hide active form
Me.Hide
Documents.Open FileName:=Fn, ReadOnly:=True, AddToRecentFiles:=False
strTable = lsbParalegal.Value
CntStr = "TABLE " & strTable
Sqlstr = "SELECT * FROM " & strTable & " WHERE " _
& "(((" & strTable & ".ID)=" _
& lsbFiles.Value & "))"

Set MyMerge = ActiveDocument.MailMerge
With MyMerge
.MainDocumentType = wdFormLetters
.OpenDataSource Name:="D:\MyFolder\MyDB.mdb", Connection:=CntStr,
SQLSTATEMENT:=Sqlstr, _
SubType:=wdMergeSubTypeWord2000, ReadOnly:=True, LinkToSource:=True,
openExclusive:=True

End With

If MyMerge.State = wdMainAndDataSource Then
MyMerge.Application.DisplayAlerts = wdAlertsNone
MyMerge.Destination = wdSendToNewDocument
MyMerge.Application.Visible = True
MyMerge.Execute pause:=False

x = ActiveDocument.Name
Documents(Fn).Close wdDoNotSaveChanges

Documents(x).Activate
Application.ScreenUpdating = True

End If

Err_handler:
Exit Sub
Para_InitError:
MsgBox "Error No: " & Err.Number & "; error message: " & Err.Description
Resume Err_handler
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top