Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail Merge with OpenRecordset problem

Status
Not open for further replies.

batteam

Programmer
Sep 12, 2003
374
US
I am trying to use MailMerge with Word from an Access 2007 (project) form, with tables in SQL. I have the following code:

Dim rsMM As ADODB.Recordset
Dim strSQLMM As String
strSQLMM = "Select * from dbo.xxx_LETTERS"

rsMM.Open strSQLMM, CurrentProject.Connection, adOpenKeyset, adLockOptimistic

Set rsMM = New ADODB.Recordset

conTemplate = "Y:\CVC USERS\nnnn\GroupLetters\documentName.dotx"

Set wrdApp = New Word.Application
Set Doc = wrdApp.Documents.Add(conTemplate)

With Doc.MailMerge

.OpenDataSource Name:=strSQLMM, _
LinkToSource:=True

.Destination = wdSendToNewDocument
.SuppressBlankLines = True

etc.
etc.

But the code always hangs at the 'OpenDataSource Name' command. I have tried many variations and nothing seems to help. Any ideas? Thanks.
 


hi,
Code:
Dim rsMM As ADODB.Recordset
Dim strSQLMM As String
strSQLMM = "Select * from dbo.xxx_LETTERS"
[b]
set rsMM = New ADODB.Recordset
[/b]
rsMM.Open strSQLMM, CurrentProject.Connection, adOpenKeyset, adLockOptimistic


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks for your help. Moving the 'Set rsMM' didn't help. I now get the error message 'File Not Found' at the .OpenDataSource Name command.

I will keep trying. Do you know if my Word document has to be in the Word template form (.dotx)? Thanks again.
 


From MS Word VBA Help
Parameters

Name Required/Optional Data Type Description
Name Required String The data source file name. You can specify a Microsoft Query (.qry) file instead of specifying a data source, a connection string, and a query string.
You specify the query string only.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I've given up on MailMerge with a SQL or recordset data source. I am now attempting to create a .csv file in VBA, but cannot get the file saved properly as a .csv file. My code is:

Dim ExcelSheet As Object
Set ExcelSheet = CreateObject("Excel.Sheet")
ExcelSheet.Application.Cells(1, 1).Value = "case_id"
ExcelSheet.SaveAs FileName:="Y:\CVC USERS\Technology\GroupLetters\RePrint_Letter.csv", _FileFormat:=xlCSV

but always get the error: 'SaveAs method of Workbook class failed'.

Any ideas? Do I have to use another method of the CreateObject?

Thanks for your help.
 



You need to CREATE the Excel.Application object, NOT a sheet object at this point. Look at the CreateObject method.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top