473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Mail merge problem

Hi everyone,

I've created a mail merge Word doc. (using Office XP) , the data source is
an Access query.

Functionality I'm attempting to set up is:
User sets a boolean field [Merge] to true for each person for whom a mail
merge letter is desired.
The query reads address info from the table for each record where [Merge] is
true.

When I open the doc via Word everything is fine, the data is loaded and the
Mail Merge toolbar is active and I can select "Merge to New Document".

I want to open this Word doc. from Access and perform the "Merge to New
Document" rather than have the user work separately in Word. I can open the
doc. successfully but the mailmerge capability isn't recognized.

Here the part of the code with the problem.

If CreateWordObj Then
gobjWord.Visible = True
gobjWord.Documents.Open CurrentProject.Path & "\" & DocName
DoEvents

' NEXT LINE FAILS with err.number = 5852 and err.description =
"requested object is not available"
gobjWord.ActiveDocument.MailMerge.Destination = wdSendToNewDocument
gobjWord.ActiveDocument.MailMerge.SuppressBlankLin es = True
gobjWord.ActiveDocument.MailMerge.Execute
gobjWord.ActiveDocument.PrintPreview
gobjWord.Visible = True
End If

If I remove the three lines which reference
gobjWord.ActiveDocument.MailMerge then the document opens in print preview
with the mail merge toolbar greyed out so 'merge to new document' is not
available. It's as though the mail merge capability of the document isn't
recognized.

thx for any insight anyone can offer.

Linda

Nov 13 '05 #1
8 9473
Linda,
I use the following code, where strDotpath is the Word template I am using,
and strDataFileName is the data source (text file). I prefer to export the
query to a text file for the merge.

Set WordObj = WordApp.Documents.Open(strDotPath)
With WordObj.MailMerge
.OpenDataSource Name:=strDataFileName
.Destination = wdSendtoNewDocument
.Execute
End With

The line with 'OpenDataSource' is the one missing from your code. I can't
say if that is your problem, but its worth a look.

If you want, I can email the entire code, but it is a bit much to post here.

--
Bob Darlington
Brisbane

"Squirrel" <wi*****@covad.net> wrote in message
news:82***************************@msgid.meganewss ervers.com...
Hi everyone,

I've created a mail merge Word doc. (using Office XP) , the data source is an Access query.

Functionality I'm attempting to set up is:
User sets a boolean field [Merge] to true for each person for whom a mail
merge letter is desired.
The query reads address info from the table for each record where [Merge] is true.

When I open the doc via Word everything is fine, the data is loaded and the Mail Merge toolbar is active and I can select "Merge to New Document".

I want to open this Word doc. from Access and perform the "Merge to New
Document" rather than have the user work separately in Word. I can open the doc. successfully but the mailmerge capability isn't recognized.

Here the part of the code with the problem.

If CreateWordObj Then
gobjWord.Visible = True
gobjWord.Documents.Open CurrentProject.Path & "\" & DocName
DoEvents

' NEXT LINE FAILS with err.number = 5852 and err.description =
"requested object is not available"
gobjWord.ActiveDocument.MailMerge.Destination = wdSendToNewDocument gobjWord.ActiveDocument.MailMerge.SuppressBlankLin es = True
gobjWord.ActiveDocument.MailMerge.Execute
gobjWord.ActiveDocument.PrintPreview
gobjWord.Visible = True
End If

If I remove the three lines which reference
gobjWord.ActiveDocument.MailMerge then the document opens in print preview
with the mail merge toolbar greyed out so 'merge to new document' is not
available. It's as though the mail merge capability of the document isn't
recognized.

thx for any insight anyone can offer.

Linda

Nov 13 '05 #2
I have a working example that "you" can use. it is automatic..

The code you need is:

With WordDoc.MailMerge
.Destination = 0 ' 0 = new doc
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = 1
' .LastRecord = 1
End With
.Execute Pause:=True
End With

However, with my "example" super word merge, the code you need is:

dim strSql as string

strSql = "select * from tblCustomer where CheckBox = True ORDER BY LastName"

MergeAllWord (strSql)

The above is all you need. So, give my sample word merge a try...as it will
save you a lot of work, you find it here:
http://www.attcanada.net/~kallal.msn.../msaccess.html

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.attcanada.net/~kallal.msn
Nov 13 '05 #3
Bob,

I have the same probvlem with a mail merge. It seems that when you try to
use a query with criteria in one of the fields for the data source, mail
merge won't accept the query. I haven't tried Albert's "super mail merge"
yet to see if it works with the query with a criteria in one of the fields.

Steve

"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:41**********************@news.optusnet.com.au ...
Linda,
I use the following code, where strDotpath is the Word template I am using, and strDataFileName is the data source (text file). I prefer to export the
query to a text file for the merge.

Set WordObj = WordApp.Documents.Open(strDotPath)
With WordObj.MailMerge
.OpenDataSource Name:=strDataFileName
.Destination = wdSendtoNewDocument
.Execute
End With

The line with 'OpenDataSource' is the one missing from your code. I can't
say if that is your problem, but its worth a look.

If you want, I can email the entire code, but it is a bit much to post here.
--
Bob Darlington
Brisbane

"Squirrel" <wi*****@covad.net> wrote in message
news:82***************************@msgid.meganewss ervers.com...
Hi everyone,

I've created a mail merge Word doc. (using Office XP) , the data source is
an Access query.

Functionality I'm attempting to set up is:
User sets a boolean field [Merge] to true for each person for whom a mail merge letter is desired.
The query reads address info from the table for each record where [Merge] is
true.

When I open the doc via Word everything is fine, the data is loaded and

the
Mail Merge toolbar is active and I can select "Merge to New Document".

I want to open this Word doc. from Access and perform the "Merge to New
Document" rather than have the user work separately in Word. I can open

the
doc. successfully but the mailmerge capability isn't recognized.

Here the part of the code with the problem.

If CreateWordObj Then
gobjWord.Visible = True
gobjWord.Documents.Open CurrentProject.Path & "\" & DocName
DoEvents

' NEXT LINE FAILS with err.number = 5852 and err.description =
"requested object is not available"
gobjWord.ActiveDocument.MailMerge.Destination =

wdSendToNewDocument
gobjWord.ActiveDocument.MailMerge.SuppressBlankLin es = True
gobjWord.ActiveDocument.MailMerge.Execute
gobjWord.ActiveDocument.PrintPreview
gobjWord.Visible = True
End If

If I remove the three lines which reference
gobjWord.ActiveDocument.MailMerge then the document opens in print

preview with the mail merge toolbar greyed out so 'merge to new document' is not
available. It's as though the mail merge capability of the document isn't recognized.

thx for any insight anyone can offer.

Linda


Nov 13 '05 #4
Steve,
That is one of the reasons I export the query to a text file, and use that
as my data source.
I use
DoCmd.TransferText acExportMerge, , queryname, "datafile.txt"
then rename the file with a .doc extension.
--
Bob Darlington
Brisbane
"Steve" <no****@nospam.spam> wrote in message
news:39*****************@newsread2.news.atl.earthl ink.net...
Bob,

I have the same probvlem with a mail merge. It seems that when you try to
use a query with criteria in one of the fields for the data source, mail
merge won't accept the query. I haven't tried Albert's "super mail merge"
yet to see if it works with the query with a criteria in one of the fields.
Steve

"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:41**********************@news.optusnet.com.au ...
Linda,
I use the following code, where strDotpath is the Word template I am

using,
and strDataFileName is the data source (text file). I prefer to export the
query to a text file for the merge.

Set WordObj = WordApp.Documents.Open(strDotPath)
With WordObj.MailMerge
.OpenDataSource Name:=strDataFileName
.Destination = wdSendtoNewDocument
.Execute
End With

The line with 'OpenDataSource' is the one missing from your code. I can't say if that is your problem, but its worth a look.

If you want, I can email the entire code, but it is a bit much to post

here.

--
Bob Darlington
Brisbane

"Squirrel" <wi*****@covad.net> wrote in message
news:82***************************@msgid.meganewss ervers.com...
Hi everyone,

I've created a mail merge Word doc. (using Office XP) , the data source
is
an Access query.

Functionality I'm attempting to set up is:
User sets a boolean field [Merge] to true for each person for whom a mail merge letter is desired.
The query reads address info from the table for each record where [Merge]
is
true.

When I open the doc via Word everything is fine, the data is loaded

and the
Mail Merge toolbar is active and I can select "Merge to New Document".

I want to open this Word doc. from Access and perform the "Merge to
New Document" rather than have the user work separately in Word. I can open the
doc. successfully but the mailmerge capability isn't recognized.

Here the part of the code with the problem.

If CreateWordObj Then
gobjWord.Visible = True
gobjWord.Documents.Open CurrentProject.Path & "\" & DocName
DoEvents

' NEXT LINE FAILS with err.number = 5852 and err.description =
"requested object is not available"
gobjWord.ActiveDocument.MailMerge.Destination =

wdSendToNewDocument
gobjWord.ActiveDocument.MailMerge.SuppressBlankLin es = True
gobjWord.ActiveDocument.MailMerge.Execute
gobjWord.ActiveDocument.PrintPreview
gobjWord.Visible = True
End If

If I remove the three lines which reference
gobjWord.ActiveDocument.MailMerge then the document opens in print

preview with the mail merge toolbar greyed out so 'merge to new document' is
not available. It's as though the mail merge capability of the document

isn't recognized.

thx for any insight anyone can offer.

Linda



Nov 13 '05 #5
Bob,

Thanks for the info about exporting the query to a text file! When you do
that, what delimiter if any do you use?

Thanks,

Steve
"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:41**********************@news.optusnet.com.au ...
Steve,
That is one of the reasons I export the query to a text file, and use that
as my data source.
I use
DoCmd.TransferText acExportMerge, , queryname, "datafile.txt"
then rename the file with a .doc extension.
--
Bob Darlington
Brisbane
"Steve" <no****@nospam.spam> wrote in message
news:39*****************@newsread2.news.atl.earthl ink.net...
Bob,

I have the same probvlem with a mail merge. It seems that when you try to
use a query with criteria in one of the fields for the data source, mail
merge won't accept the query. I haven't tried Albert's "super mail merge" yet to see if it works with the query with a criteria in one of the

fields.

Steve

"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:41**********************@news.optusnet.com.au ...
Linda,
I use the following code, where strDotpath is the Word template I am

using,
and strDataFileName is the data source (text file). I prefer to export

the query to a text file for the merge.

Set WordObj = WordApp.Documents.Open(strDotPath)
With WordObj.MailMerge
.OpenDataSource Name:=strDataFileName
.Destination = wdSendtoNewDocument
.Execute
End With

The line with 'OpenDataSource' is the one missing from your code. I can't say if that is your problem, but its worth a look.

If you want, I can email the entire code, but it is a bit much to post

here.

--
Bob Darlington
Brisbane

"Squirrel" <wi*****@covad.net> wrote in message
news:82***************************@msgid.meganewss ervers.com...
> Hi everyone,
>
> I've created a mail merge Word doc. (using Office XP) , the data source is
> an Access query.
>
> Functionality I'm attempting to set up is:
> User sets a boolean field [Merge] to true for each person for whom a

mail
> merge letter is desired.
> The query reads address info from the table for each record where

[Merge]
is
> true.
>
> When I open the doc via Word everything is fine, the data is loaded and the
> Mail Merge toolbar is active and I can select "Merge to New Document". >
> I want to open this Word doc. from Access and perform the "Merge to New > Document" rather than have the user work separately in Word. I can open the
> doc. successfully but the mailmerge capability isn't recognized.
>
> Here the part of the code with the problem.
>
> If CreateWordObj Then
> gobjWord.Visible = True
> gobjWord.Documents.Open CurrentProject.Path & "\" & DocName
> DoEvents
>
> ' NEXT LINE FAILS with err.number = 5852 and err.description = > "requested object is not available"
> gobjWord.ActiveDocument.MailMerge.Destination =
wdSendToNewDocument
> gobjWord.ActiveDocument.MailMerge.SuppressBlankLin es = True
> gobjWord.ActiveDocument.MailMerge.Execute
> gobjWord.ActiveDocument.PrintPreview
> gobjWord.Visible = True
> End If
>
> If I remove the three lines which reference
> gobjWord.ActiveDocument.MailMerge then the document opens in print

preview
> with the mail merge toolbar greyed out so 'merge to new document' is not > available. It's as though the mail merge capability of the document

isn't
> recognized.
>
> thx for any insight anyone can offer.
>
> Linda
>
>
>



Nov 13 '05 #6
Steve,
Run TransferText after selecting records and before running the merge.
TransferText creates a tab limited .txt file, but you can probably specify
another format.
Before running TransferText, I delete any existing text files created during
previous merges (using Kill) , and one called schema.ini which gets created
automatically. Before I started deleting this one, I was getting errors
after the first document was generated (but I can't remember what the error
was).
For some reason, later versions of Access won't allow the .doc extension to
be used in TransferText, and later versions of Word don't like using .txt as
a data source.
So I just rename the .txt to .doc and they both seem to be as happy as a
couple of pigs in.

By using the text file as the data source (instead of the query), you also
avoid problems in a secured db, where you can get a password prompt when you
try to open the data source.

Hope this is of some help.
--
Bob Darlington
Brisbane
"Steve" <no****@nospam.spam> wrote in message
news:gZ*****************@newsread2.news.atl.earthl ink.net...
Bob,

Thanks for the info about exporting the query to a text file! When you do
that, what delimiter if any do you use?

Thanks,

Steve
"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:41**********************@news.optusnet.com.au ...
Steve,
That is one of the reasons I export the query to a text file, and use that
as my data source.
I use
DoCmd.TransferText acExportMerge, , queryname, "datafile.txt"
then rename the file with a .doc extension.
--
Bob Darlington
Brisbane
"Steve" <no****@nospam.spam> wrote in message
news:39*****************@newsread2.news.atl.earthl ink.net...
Bob,

I have the same probvlem with a mail merge. It seems that when you try to use a query with criteria in one of the fields for the data source, mail merge won't accept the query. I haven't tried Albert's "super mail merge" yet to see if it works with the query with a criteria in one of the fields.

Steve

"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:41**********************@news.optusnet.com.au ...
> Linda,
> I use the following code, where strDotpath is the Word template I am
using,
> and strDataFileName is the data source (text file). I prefer to export the
> query to a text file for the merge.
>
> Set WordObj = WordApp.Documents.Open(strDotPath)
> With WordObj.MailMerge
> .OpenDataSource Name:=strDataFileName
> .Destination = wdSendtoNewDocument
> .Execute
> End With
>
> The line with 'OpenDataSource' is the one missing from your code. I

can't
> say if that is your problem, but its worth a look.
>
> If you want, I can email the entire code, but it is a bit much to
post here.
>
> --
> Bob Darlington
> Brisbane
>
> "Squirrel" <wi*****@covad.net> wrote in message
> news:82***************************@msgid.meganewss ervers.com...
> > Hi everyone,
> >
> > I've created a mail merge Word doc. (using Office XP) , the data

source
> is
> > an Access query.
> >
> > Functionality I'm attempting to set up is:
> > User sets a boolean field [Merge] to true for each person for whom a mail
> > merge letter is desired.
> > The query reads address info from the table for each record where
[Merge]
> is
> > true.
> >
> > When I open the doc via Word everything is fine, the data is loaded
and
> the
> > Mail Merge toolbar is active and I can select "Merge to New Document". > >
> > I want to open this Word doc. from Access and perform the "Merge
to New
> > Document" rather than have the user work separately in Word. I
can open
> the
> > doc. successfully but the mailmerge capability isn't recognized.
> >
> > Here the part of the code with the problem.
> >
> > If CreateWordObj Then
> > gobjWord.Visible = True
> > gobjWord.Documents.Open CurrentProject.Path & "\" &
DocName > > DoEvents
> >
> > ' NEXT LINE FAILS with err.number = 5852 and err.description = > > "requested object is not available"
> > gobjWord.ActiveDocument.MailMerge.Destination =
> wdSendToNewDocument
> > gobjWord.ActiveDocument.MailMerge.SuppressBlankLin es =

True > > gobjWord.ActiveDocument.MailMerge.Execute
> > gobjWord.ActiveDocument.PrintPreview
> > gobjWord.Visible = True
> > End If
> >
> > If I remove the three lines which reference
> > gobjWord.ActiveDocument.MailMerge then the document opens in print
preview
> > with the mail merge toolbar greyed out so 'merge to new document' is not
> > available. It's as though the mail merge capability of the

document isn't
> > recognized.
> >
> > thx for any insight anyone can offer.
> >
> > Linda
> >
> >
> >
>
>



Nov 13 '05 #7
Regarding extensions for the data file> I have had luck using the .tab
extension. Both TransferText and Word seem happy with it.
Nov 13 '05 #8
Thanks for that J.
I'll give it a try.

--
Bob Darlington
Brisbane
"j.mandala" <ma*****@rci.rutgers.edu> wrote in message
news:6c**************************@posting.google.c om...
Regarding extensions for the data file> I have had luck using the .tab
extension. Both TransferText and Word seem happy with it.

Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lisa | last post by:
I have a query named QryDept where one of the fields is DeptID. The query is used for the data source of a mail merge letter. I would like to control which department is to get the mail merge...
1
by: Shannon Rotz | last post by:
I'm trying to automate Word XP from Access XP with the following function. The sqlstmt argument is "Select * from where ". I understand that Microsoft Word mailmerge changed its default data...
3
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge...
4
by: pmhaupt2 | last post by:
I developed an Access 2003 program that will allow the user to produce a group of Word letters that merge with data records from an Access database. I created a mail merge Word document and...
2
by: David | last post by:
I am having problems closing winword.exe.My mail merge works ok but the word application is not closing down. Can anyone help in telling me where I am going wrong and what I am missing out of my...
0
by: Phil C. | last post by:
Hi, I'm using Access 2000. I have a Select Query that uses the MID function to separate the actual text of articles from the title of the articles. The articles are enterd into the...
0
by: mbbostwick | last post by:
I have a problem with a mail merge procedure I used to use with Access '97. We recently converted to Office XP (2002) and I now have an issue I am unfamilliar with and have been unable to...
6
by: crealesmith | last post by:
Firstly, I have no problem with mail merging to Word, VB code for that works perfectly. On one mail merge I need to merge 15 fields of data that are from 3 seperate records. The 3 records are all...
9
by: atc | last post by:
Sorry but another question from a newbie. I am trying to create a mail merge based on a query. I have a button on a form (form is based on query). I found this code in one of the discussions and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.