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

Please help! Strange behavior: Access > Word Mail Merge code

Hello all you fine folks,

Here is some code I am using to merge data from a single record Access
2K3 table into a NEW word document based on a pre-defined Word merge
template doc. All I want to happen is as follows:

User defines a storage path and name for the new Word document then
clicks a "Create" button on a form. From that point on I use the
following code:

====================== BEGIN CODE ============================
Public Sub MergeIt(docPath As String)

Dim fID As Long
Dim strSQL As String
Dim objWord As Word.Document

On Error GoTo MergeIt_Error

If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord

fID = Me.txtFaxID

strSQL = "SELECT tblSavedFaxes.FaxID, tblSavedFaxes.From,
tblSavedFaxes.FullName, " & _
"tblSavedFaxes.Facsimile, tblSavedFaxes.Telephone, " & _
"tblSavedFaxes.CID, tblSavedFaxes.[DACSFileNum],
tblSavedFaxes.Importance, " & _
"tblSavedFaxes.RE, tblSavedFaxes.MsgBody INTO
TEMP_FaxPrint " & _
"FROM tblSavedFaxes WHERE (((tblSavedFaxes.FaxID)=" & fID
& "));"

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True

Set objWord = GetObject(ProgDrive &
"\DACS\DocTemplates\FaxMerge.dot", "Word.Document")

' ' Make Word visible.
' objWord.Application.Visible = True

' Set the mail merge data source as a query on the DACS Database.

objWord.MailMerge.OpenDataSource Name:=CurrentDb.Name,
LinkToSource:=True, Connection:="TABLE TEMP_FaxPrint",
SQLStatement:="SELECT * FROM [TEMP_FaxPrint]"

objWord.MailMerge.Destination = wdSendToNewDocument

' Execute the mail merge.
objWord.MailMerge.Execute

'Save the new document per pathname provided by user (docPath)
ActiveDocument.SaveAs docPath, , , , True

' Make Word visible.
objWord.Application.Visible = True

' Close master document and release object variable
objWord.Close wdDoNotSaveChanges
Set objWord = Nothing
====================== END CODE ============================

The problem is that it works fine the FIRST time I do it (most of the
time). As soon as I try to do it again, the template gets opened in a
separate instance of Word in the background and it does not close.
Also, sometimes, a new instance of the Access app is spawned as well.

All that needs to happen is for the new word document to be opened
with the data from the one record table merged into the pre-defined
merge fields with the document already saved once. Then the user can
complete the document and click save again before they close Word --
at which point, Word should be closed and they should be right back at
the form they started from and there should be only one instance of
Access open.

Anyone have a clue what I'm missing?

Thanks for your help.

--LC

Nov 13 '05 #1
0 2153

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

Similar topics

2
by: KK | last post by:
Hi Peoples, Can anyone give me any learning materials for learning C++. i.e. can you give me any docs or give me the link to any website that has info on programming in general or C++. (ok...
3
by: Lodewijk van Haringhal | last post by:
I'am new with javascritping not with programming. Is there nobody who can help me with ths simple promblem? :) Please, please give me a hint. Please help me with this script. I have two lists in...
1
by: HolaGoogle | last post by:
Hi all, Please help me with the following..it's realy urgent and i tried everything i could and i can't get it work properly!! Thanks in advance. Here's what i'm trying to accomplish: in my...
0
by: Kurt Watson | last post by:
I’m having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web...
7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
8
by: matt.sus | last post by:
This has been driving me crazy for days: IF ANYONE CAN HELP FIX THE HTML BELOW, PLEASE HELP! (please email me at matt.sus@gmail.com - or reply here) i am trying to load up a random background...
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
2
jeffbroodwar
by: jeffbroodwar | last post by:
Hi everyone ! i need help on how can i convert xml data to resultset.. actually i was able to convert ResultSet to XML (using MySQL database) the problem is how can i make my client program consume...
9
by: FERHAT AÇICI | last post by:
hi all! who know arrays on visual basic please tell me.... thanks..
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.