473,756 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.RunComman d acCmdSaveRecord

fID = Me.txtFaxID

strSQL = "SELECT tblSavedFaxes.F axID, tblSavedFaxes.F rom,
tblSavedFaxes.F ullName, " & _
"tblSavedFaxes. Facsimile, tblSavedFaxes.T elephone, " & _
"tblSavedFaxes. CID, tblSavedFaxes.[DACSFileNum],
tblSavedFaxes.I mportance, " & _
"tblSavedFaxes. RE, tblSavedFaxes.M sgBody INTO
TEMP_FaxPrint " & _
"FROM tblSavedFaxes WHERE (((tblSavedFaxe s.FaxID)=" & fID
& "));"

DoCmd.SetWarnin gs False
DoCmd.RunSQL strSQL
DoCmd.SetWarnin gs True

Set objWord = GetObject(ProgD rive &
"\DACS\DocTempl ates\FaxMerge.d ot", "Word.Document" )

' ' Make Word visible.
' objWord.Applica tion.Visible = True

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

objWord.MailMer ge.OpenDataSour ce Name:=CurrentDb .Name,
LinkToSource:=T rue, Connection:="TA BLE TEMP_FaxPrint",
SQLStatement:=" SELECT * FROM [TEMP_FaxPrint]"

objWord.MailMer ge.Destination = wdSendToNewDocu ment

' Execute the mail merge.
objWord.MailMer ge.Execute

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

' Make Word visible.
objWord.Applica tion.Visible = True

' Close master document and release object variable
objWord.Close wdDoNotSaveChan ges
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 2184

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

Similar topics

2
2013
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 I know I could go to a library and read books on C++ but looking for something urgently.)
3
2324
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 my form. One to choose a directory and one to choose a picture. The script bellow works perfect without the directory choose function. I tried to make the directory choose function myself but I did not succeed. I think I made a mistake here:...
1
2004
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 form i have a table with 3 rows (3 input text), in which user can enter values and then clik save. When he clicks the Save button, i'd like to be able to add the created items to the end of my table
0
1702
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 browser that Hotmail does not support. If you continue to use your current browser software we cannot guarantee that Hotmail will work correctly for you". Please help, this is very annoying. I have been searching for help on
7
2392
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 me. This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of our text. I have done Exercise 7 for you: Below you will find the ADT specification for a string of characters. It represents slightly more that a minimal string...
8
1339
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 image which is the background for the table. at the moment the image in the html is named 1.jpg (and i woulld like it to rotate with 3 other images 2.jpg, 3.jpg, 4.jpg)
13
2149
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 will fall somewhere between a Start & End time Further more, there will be Break & Lunch times between Start & End. Example... Start 08:00 Break start 10:30
2
2307
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 this xml file... please someone help me with this.... if possible also help me do the research.. i need to finish this before next week. no worries, it'll pay you good. knowing that only few people knows how to do this. it an achievement to be one of...
9
1981
by: FERHAT AÇICI | last post by:
hi all! who know arrays on visual basic please tell me.... thanks..
0
9455
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
9271
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,...
0
9708
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7242
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
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
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
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2665
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.