mail merge problems

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to automate a mail merge from a form in my access 2002 database. I've
tried importing the code from a recommended site

http://www.attcanada.net/~kallal.msn/msaccess/msaccess.html


but keep getting an error - 424 -object required, something to do with the
line ...

Set WordDoc = wordApp.Documents.Add

I have no coding experience but i need this to work - any help would be
greatly appreciated!!

Thanks
 
Hi All,

sorry to post a question as a follow up to this query, i didn't know
how to put a new one.

I need to create labels off of my web site from a text file with
customer address information (or SQL database using a query) using
mail merge in word, programatically.

I'm using the following sample code (relevant parts) to do the same.
but it gets hung on the open datasource part.

I was able to see it the first time, not the data in the text file,
but it opened the mail merged word document with 2 lines, record1
contains too few records, record2 contains too few records..

now, the code doesn't do anything , but just hung on open datasource
part.

Any suggestions?

Any help would be greatly appreciated

Thanks,
E.

Sample Code.


Word.Application wrdApp;

Word._Document oDataDoc;



wrdApp = new Word.Application();
wrdApp.Visible = true;



object oTrue = true;



oDataDoc = wrdApp.Documents.Add(ref Template, ref oMissing, ref
oMissing, ref oFalse);

object oFormat = "wdOpenFormatAuto";
object oEmpty = "";

object oSubtype = Word.WdMergeSubType.wdMergeSubTypeOther ;




oDataDoc.MailMerge.MainDocumentType =
WdMailMergeMainDocType.wdMailingLabels;


oDataDoc.MailMerge.OpenDataSource("C:\\Els_Import\\MailMergeXCL.txt", //sName,
ref oFormat, //wdOpenFormatText
ref oFalse, //ConfirmConversions
ref oFalse, //ReadOnly
ref oFalse, //LinkToSource
ref oFalse, //AddToRecentFiles
ref oEmpty, //PasswordDocument
ref oEmpty, //PasswordTemplate
ref oFalse, //Revert
ref oEmpty, //WritePasswordDocument
ref oEmpty, //WritePasswordTemplate
ref oEmpty, //Connection
ref oEmpty, //SQLStatement
ref oEmpty, //SQLStatement1
ref oFalse,
ref oSubtype
);



oDataDoc.MailMerge.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument;

oDataDoc.MailMerge.Execute(ref oFalse);
 
I assume that you have added a Reference to the Word Library in your
VBA Project.

I also assume that you have Dimensioned WordDoc As Word.Document. Have
you Dimensioned and initialised wordApp in the preceding code? e.g.:

Dim wordApp As Word.Application
Set wordApp = New Word.Application

If you have no coding experience, I am afraid that Office Automation
coding is not the ideal place to start! If what you are trying to
Automate is a simple Mail Merge, you would almost certainly be better
off doing it from Word after creating an appropriate Query in Access
as the source for the Merge. Word Automation is often a good solution
for more complex reporting problems, and I use it extensively, but
Reports and Word mail-merges can do a lot, much more simply.

I need to automate a mail merge from a form in my access 2002 database. I've
tried importing the code from a recommended site

http://www.attcanada.net/~kallal.msn/msaccess/msaccess.html


but keep getting an error - 424 -object required, something to do with the
line ...

Set WordDoc = wordApp.Documents.Add

I have no coding experience but i need this to work - any help would be
greatly appreciated!!

Thanks


Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher
 
Back
Top