473,386 Members | 1,609 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,386 software developers and data experts.

Mail merge problem

28
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command36_Click()
  2. Set objWord = GetObject("C:\Documents and Settings\xxxx\My Documents\merge.doc", "Word.Document")
  3. 'turn off alerts
  4. objWord.Application.DisplayAlerts = wdAlertsNone
  5. ' Make Word visible.
  6. objWord.Application.Visible = True
  7. ' Set the mail merge data source as the OLF Front End database.
  8. objWord.MailMerge.OpenDataSource _
  9. Name:="C:\Documents and Settings\xxxx\My Documents\NewSystem.mdb", _
  10. LinkToSource:=True, _
  11. Connection:=strConnect
  12. objWord.MailMerge.DataSource.QueryString
  13. ' Execute the mail merge.
  14. objWord.MailMerge.Execute
  15. End Sub
  16.  
I get an error saying "Runtime error 13: type mismatch" and this code is highlighted:
Expand|Select|Wrap|Line Numbers
  1. objWord.MailMerge.OpenDataSource _
  2. Name:="C:\Documents and Settings\Ewan Farr\My Documents\NewSystem.mdb", _
  3. LinkToSource:=True, _
  4. Connection:=strConnect
  5.  
Any ideas what is wrong or is the code right in the 1st place?
Thanks
ATC
Mar 5 '07 #1
9 2340
ADezii
8,834 Expert 8TB
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command36_Click()
  2. Set objWord = GetObject("C:\Documents and Settings\xxxx\My Documents\merge.doc", "Word.Document")
  3. 'turn off alerts
  4. objWord.Application.DisplayAlerts = wdAlertsNone
  5. ' Make Word visible.
  6. objWord.Application.Visible = True
  7. ' Set the mail merge data source as the OLF Front End database.
  8. objWord.MailMerge.OpenDataSource _
  9. Name:="C:\Documents and Settings\xxxx\My Documents\NewSystem.mdb", _
  10. LinkToSource:=True, _
  11. Connection:=strConnect
  12. objWord.MailMerge.DataSource.QueryString
  13. ' Execute the mail merge.
  14. objWord.MailMerge.Execute
  15. End Sub
  16.  
I get an error saying "Runtime error 13: type mismatch" and this code is highlighted:
Expand|Select|Wrap|Line Numbers
  1. objWord.MailMerge.OpenDataSource _
  2. Name:="C:\Documents and Settings\Ewan Farr\My Documents\NewSystem.mdb", _
  3. LinkToSource:=True, _
  4. Connection:=strConnect
  5.  
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:
Expand|Select|Wrap|Line Numbers
  1. strConnect = "Provider=Microsoft.Jet.OLEDB.4.0
Mar 5 '07 #2
atc
28
Thanks for your help.
Now I am getting an error for
Expand|Select|Wrap|Line Numbers
  1. objWord.MailMerge.DataSource.QueryString
  2.  
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
Mar 6 '07 #3
ADezii
8,834 Expert 8TB
Thanks for your help.
Now I am getting an error for
Expand|Select|Wrap|Line Numbers
  1. objWord.MailMerge.DataSource.QueryString
  2.  
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.
Expand|Select|Wrap|Line Numbers
  1. Dim Doc As Document
  2. Dim MyDS As MailMergeDataSource
  3.  
  4. Set Doc = ????
  5. Set MyDS = Doc.MailMerge.DataSource
Mar 6 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
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 ...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command36_Click()
  2. Dim WordApp As New Word.Application        
  3. Dim WordDoc As Word.Document        
  4. Dim MailMerge As Word.MailMerge           
  5.  
  6. WordApp.Visible = True
  7. Set WordDoc = WordApp.Documents.Open("C:\Documents and Settings\xxxx\My Documents\merge.doc", True)        
  8.  
  9. Set MailMerge = WordDoc.MailMerge           
  10.  
  11. With MailMerge
  12.    .OpenDataSource Name:="C:\Documents and Settings\xxxx\My Documents\NewSystem.mdb", _ 
  13.       LinkToSource:=True, _
  14.       Connection:="TABLE Name" ' put name of table instead of name here or
  15.       ' if using a query put QUERY Name
  16.     ' Execute the mail merge.
  17.    .Execute
  18. End With
  19.  
  20. End Sub
  21.  
Mary
Mar 6 '07 #5
atc
28
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
Mar 7 '07 #6
atc
28
If I click cancel when the message box comes up. My templete does not merge but the new document does not appear.
ATC
Mar 7 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
John

Did you change this line of code to reflect your query name.
Expand|Select|Wrap|Line Numbers
  1. Connection:="TABLE Name" ' put name of table instead of name here or
  2.       ' if using a query put QUERY Name
  3.  
Assuming a query named qryDummy ...
Expand|Select|Wrap|Line Numbers
  1. Connection:="QUERY qryDummy" 
  2.  
Mary
Mar 9 '07 #8
atc
28
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
Mar 10 '07 #9
MMcCarthy
14,534 Expert Mod 8TB
Sorry John

Not at the moment but I'll see if I can find out anything else.

Mary
Mar 11 '07 #10

Sign in to post your reply or Sign up for a free account.

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...
8
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...
9
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...
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...
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...
3
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...
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...
7
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...
0
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,...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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...
0
Oralloy
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,...
0
jinu1996
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...

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.