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 tried to modify it for my needs. -
Private Sub Command36_Click()
-
Set objWord = GetObject("C:\Documents and Settings\xxxx\My Documents\merge.doc", "Word.Document")
-
'turn off alerts
-
objWord.Application.DisplayAlerts = wdAlertsNone
-
' Make Word visible.
-
objWord.Application.Visible = True
-
' Set the mail merge data source as the OLF Front End database.
-
objWord.MailMerge.OpenDataSource _
-
Name:="C:\Documents and Settings\xxxx\My Documents\NewSystem.mdb", _
-
LinkToSource:=True, _
-
Connection:=strConnect
-
objWord.MailMerge.DataSource.QueryString
-
' Execute the mail merge.
-
objWord.MailMerge.Execute
-
End Sub
-
I get an error saying "Runtime error 13: type mismatch" and this code is highlighted: -
objWord.MailMerge.OpenDataSource _
-
Name:="C:\Documents and Settings\Ewan Farr\My Documents\NewSystem.mdb", _
-
LinkToSource:=True, _
-
Connection:=strConnect
-
Any ideas what is wrong or is the code right in the 1st place?
Thanks
ATC
9 2340
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 tried to modify it for my needs. -
Private Sub Command36_Click()
-
Set objWord = GetObject("C:\Documents and Settings\xxxx\My Documents\merge.doc", "Word.Document")
-
'turn off alerts
-
objWord.Application.DisplayAlerts = wdAlertsNone
-
' Make Word visible.
-
objWord.Application.Visible = True
-
' Set the mail merge data source as the OLF Front End database.
-
objWord.MailMerge.OpenDataSource _
-
Name:="C:\Documents and Settings\xxxx\My Documents\NewSystem.mdb", _
-
LinkToSource:=True, _
-
Connection:=strConnect
-
objWord.MailMerge.DataSource.QueryString
-
' Execute the mail merge.
-
objWord.MailMerge.Execute
-
End Sub
-
I get an error saying "Runtime error 13: type mismatch" and this code is highlighted: -
objWord.MailMerge.OpenDataSource _
-
Name:="C:\Documents and Settings\Ewan Farr\My Documents\NewSystem.mdb", _
-
LinkToSource:=True, _
-
Connection:=strConnect
-
Any ideas what is wrong or is the code right in the 1st place?
Thanks
ATC
You haven't defined strConnect. It should look something like: - strConnect = "Provider=Microsoft.Jet.OLEDB.4.0
Thanks for your help.
Now I am getting an error for -
objWord.MailMerge.DataSource.QueryString
-
The error is "QueryString is not a method"
Also when word is lanuched I have to select the query i want to merge. Is there any way I can get round this.
Thanks again
ATC
Thanks for your help.
Now I am getting an error for -
objWord.MailMerge.DataSource.QueryString
-
The error is "QueryString is not a method"
Also when word is lanuched I have to select the query i want to merge. Is there any way I can get round this.
Thanks again
ATC
I think your syntax is all wrong. This is not my Field, but it seems you need to Declare an Object as MailMergeDataSource and a Document Object in order to accomplish this, not a reference to a Word Object. - Dim Doc As Document
-
Dim MyDS As MailMergeDataSource
-
-
Set Doc = ????
-
Set MyDS = Doc.MailMerge.DataSource
John
There are a couple of things here.
1. Make sure the Office Word library is ticked in the Tools - References list.
2. I'm not sure if you've correctly declared your variables.
3. I'm assuming you are trying to automate Word from Access and not the other way around.
Try this code ... -
Private Sub Command36_Click()
-
Dim WordApp As New Word.Application
-
Dim WordDoc As Word.Document
-
Dim MailMerge As Word.MailMerge
-
-
WordApp.Visible = True
-
Set WordDoc = WordApp.Documents.Open("C:\Documents and Settings\xxxx\My Documents\merge.doc", True)
-
-
Set MailMerge = WordDoc.MailMerge
-
-
With MailMerge
-
.OpenDataSource Name:="C:\Documents and Settings\xxxx\My Documents\NewSystem.mdb", _
-
LinkToSource:=True, _
-
Connection:="TABLE Name" ' put name of table instead of name here or
-
' if using a query put QUERY Name
-
' Execute the mail merge.
-
.Execute
-
End With
-
-
End Sub
-
Mary
Thanks for your help mary. I modified your code for my database. Word loads as expected but word brings up a message box called "select table". It has queries and tables in it. So I select the query I want. Then word loads up a new document called "Form Letters1". It is the same as my template. Is there any way to modify the code so the message box does not appear and the new document is not created.
Thanks again
ATC
If I click cancel when the message box comes up. My templete does not merge but the new document does not appear.
ATC
John
Did you change this line of code to reflect your query name. -
Connection:="TABLE Name" ' put name of table instead of name here or
-
' if using a query put QUERY Name
-
Assuming a query named qryDummy ... -
Connection:="QUERY qryDummy"
-
Mary
Yes i changed the line of code so its revelvent to my project.
So i have no idea whats up with it.
Any more ideas?
john
Sorry John
Not at the moment but I'll see if I can find out anything else.
Mary
Sign in to post your reply or Sign up for a free account.
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: Squirrel |
last post by:
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 to true for...
|
by: Neil Ginsberg |
last post by:
I have a strange situation using Access to automate a Word mail merge. Using
Access 2000 and Word 2000, the code opens Word, opens the document in Word,
sets a table
in the calling Access...
|
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: 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: cdelarte |
last post by:
I would like to be able to mail merge records from multiple mysql
tables using a simple template, preferably via a command line script.
MSWord mail merge via ODBC will not work for me as it only...
|
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: =?Utf-8?B?QmFkaXM=?= |
last post by:
Hi,
I'm trying to follow a mail merging example in C#.Net that I got from:
http://support.microsoft.com/default.aspx/kb/301659
and in one the methods:
Word.Application wrdApp;
Word._Document...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |