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 8 9331
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
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
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
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
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 > > >
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 > > > > > > > >
Regarding extensions for the data file> I have had luck using the .tab
extension. Both TransferText and Word seem happy with it.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
header("Location:".$urlback);
Is this the right layout the...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
| |