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

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_Click()
On Error GoTo Err_CmdMailMerge_Click
Dim dbs As DAO.Database
Set dbs = Application.CurrentDb
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("EscalationMailMerge")
qdef.Parameters(0) = EscalationCalculationDate
Set rst = qdef.OpenRecordset()

Call ActivateWrdDoc("MailMerge.doc")

rst.Close
Set rstTable = Nothing
Set rst = Nothing

dbs.Close
Set dbs = Nothing

Exit_CmdMailMerge_Click:
DoCmd.Hourglass False
Exit Sub

Err_CmdMailMerge_Click:
MsgBox Err.Description
Resume Exit_CmdMailMerge_Click
End sub
Sub ActivateWrdDoc(somedoc As String)

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

' Make Word visible.
wrd.Visible = True

On Error GoTo AGAIN
wrd.Documents.Open "K:\ct\" & somedoc '<- the somedoc variable has
"somedoc.doc"
Set WordDoc = wrd.ActiveDocument
On Error GoTo ErrorHandler

' Execute the mail merge.
WordDoc.MailMerge.Execute
WordDoc.Close SaveChanges:=wdDoNotSaveChanges
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 3047
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.google.c om...
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_Click()
On Error GoTo Err_CmdMailMerge_Click
Dim dbs As DAO.Database
Set dbs = Application.CurrentDb
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("EscalationMailMerge")
qdef.Parameters(0) = EscalationCalculationDate
Set rst = qdef.OpenRecordset()

Call ActivateWrdDoc("MailMerge.doc")

rst.Close
Set rstTable = Nothing
Set rst = Nothing

dbs.Close
Set dbs = Nothing

Exit_CmdMailMerge_Click:
DoCmd.Hourglass False
Exit Sub

Err_CmdMailMerge_Click:
MsgBox Err.Description
Resume Exit_CmdMailMerge_Click
End sub
Sub ActivateWrdDoc(somedoc As String)

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

' Make Word visible.
wrd.Visible = True

On Error GoTo AGAIN
wrd.Documents.Open "K:\ct\" & somedoc '<- the somedoc variable has
"somedoc.doc"
Set WordDoc = wrd.ActiveDocument
On Error GoTo ErrorHandler

' Execute the mail merge.
WordDoc.MailMerge.Execute
WordDoc.Close SaveChanges:=wdDoNotSaveChanges
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
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...
3
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...
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: 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...
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: 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...
8
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...
1
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...
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?
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...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.