473,602 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access Parameter Query to Word Merge

Access/Word 2000

I am trying to merge a word document with an access query that has a
parameter attached to it.

Could someone please suggest how to stop the parameter from appearing
when the query runs.

I think it might have something to do with the source document
mailmerge.doc. Could it be that I'm trying to run the query from
access using dao but the file is setup for dde??

Please, I just want the user to press a button and run the query, they
have already given me the date in a text box on the form this is
attached to.

I hope I have given you enough information, if more is needed please
let me know.

Any suggestions are gratefully welcomed.

Thanks, Lynn

Code
+++++++++++++++ +++++++++++++++ ++++++++

Private Sub CmdMailMerge_Cl ick()
On Error GoTo Err_CmdMailMerg e_Click
Dim dbs As DAO.Database
Set dbs = Application.Cur rentDb
Dim qdef As DAO.QueryDef
Dim rst As DAO.Recordset, rstTable As DAO.Recordset
Dim tbf As TableDef
Dim fld As DAO.Field

DoCmd.Hourglass True

Set qdef = dbs.QueryDefs(" EscalationMailM erge")
qdef.Parameters (0) = EscalationCalcu lationDate
Set rst = qdef.OpenRecord set()

Call ActivateWrdDoc( "MailMerge.doc" )

rst.Close
Set rstTable = Nothing
Set rst = Nothing

dbs.Close
Set dbs = Nothing

Exit_CmdMailMer ge_Click:
DoCmd.Hourglass False
Exit Sub

Err_CmdMailMerg e_Click:
MsgBox Err.Description
Resume Exit_CmdMailMer ge_Click
End sub
Sub ActivateWrdDoc( somedoc As String)

AGAIN: On Error Resume Next
Set wrd = GetObject(, "Word.Applicati on")
If Err.Number = 429 Or Err.Number = 462 Then
Err.Clear
Set wrd = CreateObject("W ord.Application ")
End If

' Make Word visible.
wrd.Visible = True

On Error GoTo AGAIN
wrd.Documents.O pen "K:\ct\" & somedoc '<- the somedoc variable has
"somedoc.do c"
Set WordDoc = wrd.ActiveDocum ent
On Error GoTo ErrorHandler

' Execute the mail merge.
WordDoc.MailMer ge.Execute
WordDoc.Close SaveChanges:=wd DoNotSaveChange s
Set WordDoc = Nothing
Set wrd = Nothing
On Error GoTo 0
Exit_Sub:
Exit Sub
ErrorHandler:
MsgBox Err.Description
Err.Clear
Resume Exit_Sub
End Sub
Nov 13 '05 #1
3 3064
I know this doesn't directly answer your question but because of various
issues and quirks of automated mailmerge (especially the one where Word
launches a new copy of your database if it has anything displayed in the
title bar except "Microsoft Access", I tend to export the dataset to a CSV
file and then mailmerge to that instead of directly to the query.
--
Shane Suebsahakarn
----
Head of IT
PAN Telecom
Tel: +44 (0) 870 757 7001

"Lynn A." <ly***********@ hotmail.com> wrote in message
news:f0******** *************** ***@posting.goo gle.com...
Access/Word 2000

I am trying to merge a word document with an access query that has a
parameter attached to it.

Could someone please suggest how to stop the parameter from appearing
when the query runs.

I think it might have something to do with the source document
mailmerge.doc. Could it be that I'm trying to run the query from
access using dao but the file is setup for dde??

Please, I just want the user to press a button and run the query, they
have already given me the date in a text box on the form this is
attached to.

I hope I have given you enough information, if more is needed please
let me know.

Any suggestions are gratefully welcomed.

Thanks, Lynn

Code
+++++++++++++++ +++++++++++++++ ++++++++

Private Sub CmdMailMerge_Cl ick()
On Error GoTo Err_CmdMailMerg e_Click
Dim dbs As DAO.Database
Set dbs = Application.Cur rentDb
Dim qdef As DAO.QueryDef
Dim rst As DAO.Recordset, rstTable As DAO.Recordset
Dim tbf As TableDef
Dim fld As DAO.Field

DoCmd.Hourglass True

Set qdef = dbs.QueryDefs(" EscalationMailM erge")
qdef.Parameters (0) = EscalationCalcu lationDate
Set rst = qdef.OpenRecord set()

Call ActivateWrdDoc( "MailMerge.doc" )

rst.Close
Set rstTable = Nothing
Set rst = Nothing

dbs.Close
Set dbs = Nothing

Exit_CmdMailMer ge_Click:
DoCmd.Hourglass False
Exit Sub

Err_CmdMailMerg e_Click:
MsgBox Err.Description
Resume Exit_CmdMailMer ge_Click
End sub
Sub ActivateWrdDoc( somedoc As String)

AGAIN: On Error Resume Next
Set wrd = GetObject(, "Word.Applicati on")
If Err.Number = 429 Or Err.Number = 462 Then
Err.Clear
Set wrd = CreateObject("W ord.Application ")
End If

' Make Word visible.
wrd.Visible = True

On Error GoTo AGAIN
wrd.Documents.O pen "K:\ct\" & somedoc '<- the somedoc variable has
"somedoc.do c"
Set WordDoc = wrd.ActiveDocum ent
On Error GoTo ErrorHandler

' Execute the mail merge.
WordDoc.MailMer ge.Execute
WordDoc.Close SaveChanges:=wd DoNotSaveChange s
Set WordDoc = Nothing
Set wrd = Nothing
On Error GoTo 0
Exit_Sub:
Exit Sub
ErrorHandler:
MsgBox Err.Description
Err.Clear
Resume Exit_Sub
End Sub

Nov 13 '05 #2
Yet another indirect answer... Use Albert Kallal's code that outputs
the data to a csv file and then tell Word to use that. His code does
all that pretty much for you. All you have to do is specify the query
and the template you're merging to.
Nov 13 '05 #3
Yet another indirect answer... Use Albert Kallal's code that outputs
the data to a csv file and then tell Word to use that. His code does
all that pretty much for you. All you have to do is specify the query
and the template you're merging to.

Uhh... yeah, the link would be nice...

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

scroll down until you see "Super Easy Word Merge"
Nov 13 '05 #4

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

Similar topics

3
2341
by: Mark Horton | last post by:
I thought would be a super simple project, but I was wrong. I need Help!!!! I am using the Word.Application.Mailmerge.OpenDataSource to try and send a Dynamic Query to my stated Document.Open File. For the life of me I cannot fiqure out how to pass a parameter from this code to the "Proposal" Query in the Access Front End. If I do not add the param variable then everthing works fine except that it pulls all of the matching records...
3
479
by: di | last post by:
I have a Access Database, and I would like to create a word document that (preferable would filter)links to ACCESS table or query. I would like to print the word document on the filtered record that I have selected in Access. for example if I have customer number (201) that I would like to merge over to a Word document. The word document is a template that I would like to use regularly. Thanks so Much for anyone that can WALK me thru...
9
4316
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 application as the data source, and then performs a merge. Everything works fine. However, when a user uses it in Access 2002 and Word 2002, an extra instance of the Access application is opened and remains open at the end. Sometimes it remains open
3
2358
by: Strasser | last post by:
In Access2000 mass emailing worked perfectly (very powerful tool!). Doesn't work when using XP version of both Access and Outlook, even though I checked the box to ensure that I was sending the email. Any ideas? Thanks in advance.
3
5574
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 document in Word; 2. opens the document and runs the merge process for the new data. I have managed to write the code to perform step 1 ok, but I'm having trouble with step 2. It opens the word document fine but does not perform the mail merge of...
4
7464
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 associated it with a specific query in my Access database. My problem is that when I run my "create letters" button from an Access form, the program opens up Word correctly with the proper letter. However, the MailMerge toolbar in Word appears...
0
1641
by: Sheila | last post by:
I have set up a Word mail merge document of the type Directory which allows me to display all of the records on a single page rather than putting each record on a separate page. It uses a temporary table in MS Access as its datasource (loaded via a Make Table query). If I create the temporary table and then open the mail merge document from within MS Word and click "Merge to New Document", the information from the temporary table is...
8
6697
by: babyangel43 | last post by:
Hello, I have a query set up in Access. I run it monthly, changing "date of test". I would like this query to be merged with a Word document so that the cover letter is created in Word, the fields from Access are automatically filled into the Word document. The query could be anywhere from 0-5000 names, one cover letter per name. AND to this cover letter for each applicant, there has to be attached a two page document. How in the world can...
1
5047
by: kayberrie | last post by:
I want to write a VBA mail merge code. I want to link the code/macro/dohicky to a nifty little button so it makes life easy. I think I can handle the button part, the code part - not so much. I know very little (actually probably nothing) about VBA and I'm currently learning my way around Access. Basically, I want to click a button in the form that merges the letter for me, only for the one record I'm currently viewing..not the whole...
0
7993
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7920
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5867
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2418
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.