D
Diane
Group,
I am wanting to create a macro that will connect to a file in code and
perform a mail merge to outlook, the file I connect to will always be the
same file.
I am currently connecting with an ODBC connection, I want to change
this....I don't want to be running around installing this on many pc's. If I
can create an ado connection in code, I can eliminate this problem. Also,
my current macro displays the mail merge dialogue box, I don't want that
either, my goal is to connect to my file, complete a mail merge, all within
code, without user intervention.
I can connect to my database, but I can't seem to get the document to merge
with it??
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strsql As String
Set rst = New ADODB.Recordset
Const cnnstring = "Provider=IBMDA400; Data Source=iSeries"
strsql = "select * from mylib.myfile"
--->(this doesn't work for me)--->ActiveDocument.mailmerge.OpenDataSource
name:=cnnstring
--->this is step #2 that I want to work----->
With ActiveDocument.mailmerge
.Destination = wdSendToEmail
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute pause:=False
End With
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Any examples of creating this in code would be appreciated!!
I am wanting to create a macro that will connect to a file in code and
perform a mail merge to outlook, the file I connect to will always be the
same file.
I am currently connecting with an ODBC connection, I want to change
this....I don't want to be running around installing this on many pc's. If I
can create an ado connection in code, I can eliminate this problem. Also,
my current macro displays the mail merge dialogue box, I don't want that
either, my goal is to connect to my file, complete a mail merge, all within
code, without user intervention.
I can connect to my database, but I can't seem to get the document to merge
with it??
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strsql As String
Set rst = New ADODB.Recordset
Const cnnstring = "Provider=IBMDA400; Data Source=iSeries"
strsql = "select * from mylib.myfile"
--->(this doesn't work for me)--->ActiveDocument.mailmerge.OpenDataSource
name:=cnnstring
--->this is step #2 that I want to work----->
With ActiveDocument.mailmerge
.Destination = wdSendToEmail
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute pause:=False
End With
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Any examples of creating this in code would be appreciated!!