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

Mail Merge Problem

I am having problems closing winword.exe.My mail merge works ok but the word
application is not closing down. Can anyone help in telling me where I am
going wrong and what I am missing out of my code. Ihave had suggestions but
nothing as worked up to now.
Many thanks
Dave
Public Sub Fire()
'On Error GoTo Err_Fire
Dim db As Database
Dim rst As Recordset
'Dim olkApp As Outlook.Application
'Dim objmailitem As Outlook.MailItem
Dim objscript
'Dim SafeItem
'Dim utils
'Dim strAttach As String
'Dim strfilename As String
Dim objWord As Word.Document

Set objscript = CreateObject("Scripting.FileSystemObject")
If Not objscript.FolderExists("D:\" & "Fire\") Then
objscript.createfolder ("D:\" & "Fire\")
End If
If Dir("D:\Fire\*.doc") <> "" Then
Kill "D:\Fire\*.doc"
End If
Set objscript = Nothing
'On Error Resume Next
Set db = CurrentDb
Set rst = db.OpenRecordset("tblrelmanager")

Set objWord = GetObject("C:\Documents and Settings\David\Desktop\fire
risk assessment.doc", "Word.Document")

' Make Word visible.

objWord.Application.Visible = True
Do Until rst.EOF

' Set the mail merge data source as the WSS database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\David\Desktop\WSS.mdb", _
LinkToSource:=True, _
Connection:="table qryAccenture", _
SQLStatement:="SELECT * FROM [qryAccenture] WHERE [Relationship
Manager] = '" & rst![Relationship Manager] & "'"

' Execute the mail merge.
objWord.MailMerge.Execute

ActiveDocument.SaveAs FileName:="D:\fire\" & rst![Relationship Manager]
ActiveDocument.Close
rst.MoveNext
Loop

'objWord.Application.Quit False
objWord.Close
Set objWord = Nothing

rst.Close
Set rst = Nothing
db.Close
Set db = Nothing

DoCmd.SetWarnings True


Exit_Fire:
Exit Sub

Err_Fire:
MsgBox Err.Description
Resume Exit_Fire

End Sub

Nov 13 '05 #1
2 1773
where's the problem closing Word? You never explicitly close Word in
your code. Did you want it to close if it wasn't open when you started
(when GetObject is called)? If so, you could use fIsAppRunning from
AccessWeb and store it somewhere.

dim blnIsRunning as Boolean
blnIsRunning=fIsAppRunning("Word") '<--I'm guessing about the syntax
....do your thing...

Then
if not blnIsRunning Then '---Word was not running
appWord.Quit
End If

Nov 13 '05 #2
It would be polite to mention that you are asking elsewhere
(microsoft.public.access.modulesdaovba) so that multiple people are not
working on this, each unaware that others are duplicating the work.

"David" <da***********@btinternet.com> wrote in message
news:dc**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
I am having problems closing winword.exe.My mail merge works ok but the
word
application is not closing down. Can anyone help in telling me where I am
going wrong and what I am missing out of my code. Ihave had suggestions
but
nothing as worked up to now.
Many thanks
Dave
Public Sub Fire()
'On Error GoTo Err_Fire
Dim db As Database
Dim rst As Recordset
'Dim olkApp As Outlook.Application
'Dim objmailitem As Outlook.MailItem
Dim objscript
'Dim SafeItem
'Dim utils
'Dim strAttach As String
'Dim strfilename As String
Dim objWord As Word.Document

Set objscript = CreateObject("Scripting.FileSystemObject")
If Not objscript.FolderExists("D:\" & "Fire\") Then
objscript.createfolder ("D:\" & "Fire\")
End If
If Dir("D:\Fire\*.doc") <> "" Then
Kill "D:\Fire\*.doc"
End If
Set objscript = Nothing
'On Error Resume Next
Set db = CurrentDb
Set rst = db.OpenRecordset("tblrelmanager")

Set objWord = GetObject("C:\Documents and Settings\David\Desktop\fire
risk assessment.doc", "Word.Document")

' Make Word visible.

objWord.Application.Visible = True
Do Until rst.EOF

' Set the mail merge data source as the WSS database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\David\Desktop\WSS.mdb", _
LinkToSource:=True, _
Connection:="table qryAccenture", _
SQLStatement:="SELECT * FROM [qryAccenture] WHERE [Relationship
Manager] = '" & rst![Relationship Manager] & "'"

' Execute the mail merge.
objWord.MailMerge.Execute

ActiveDocument.SaveAs FileName:="D:\fire\" & rst![Relationship Manager]
ActiveDocument.Close
rst.MoveNext
Loop

'objWord.Application.Quit False
objWord.Close
Set objWord = Nothing

rst.Close
Set rst = Nothing
db.Close
Set db = Nothing

DoCmd.SetWarnings True


Exit_Fire:
Exit Sub

Err_Fire:
MsgBox Err.Description
Resume Exit_Fire

End Sub

Nov 13 '05 #3

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

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.