Suppressing Word's Save Message

S

scott

From Access, I have a Mail Merge button that lauches a Word template with
labels that populates it with database records. After the code finishes, i'm
left with 2 word docs open. 1 is the template doc that i do not wish to save
and the merged word label doc with the data.

On my access form that contains the Mail Merge button, i have a Close button
that runs CloseWord()

When I click Close button, Word displays the Save dialog on the
labeladdress.doc template file. I never want the user to save the template
file and would like to close it without the dialog to display the Save
dialog option.

Is this possible?

=========================================================================
Public gobjWord As Word.Application

Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("C:\data\labeladdress.doc",
"Word.Document")
' Make Word visible.
objWord.Application.Visible = True

objWord.MailMerge.OpenDataSource _
Name:="C:\data\" & _
"company_data.mdb", _
LinkToSource:=True, _
Connection:="TABLE tblEmployees", _
SQLStatement:="Select * from [tblEmployees]"
objWord.MailMerge.Execute
End Function

Function CreateWordObj()
On Error GoTo CreateWordObj_Err
CreateWordObj = False
'Attempt to Launch Word
Set gobjWord = New Word.Application
CreateWordObj = True

CreateWordObj_Exit:
Exit Function

CreateWordObj_Err:
MsgBox "Couldn't Launch Word!!", vbCritical, "Warning!!"
CreateWordObj = False
Resume CreateWordObj_Exit
End Function

Sub CloseWord()
If Not gobjWord Is Nothing Then
gobjWord.Quit
End If

CloseWord_Exit:
Set gobjWord = Nothing
Exit Sub

CloseWord_Err:
MsgBox "Error # " & Err.Number & ": " & Err.Description
Resume CloseWord_Exit
End Sub
 
A

Arvin Meyer

Try this:

gobjWord.ActiveDocument.Close (wdDoNotSaveChanges)

where I've commented below.

Sub CloseWord()
If Not gobjWord Is Nothing Then
gobjWord.Quit ' Do it here instead of quit
End If

CloseWord_Exit:
Set gobjWord = Nothing
Exit Sub

CloseWord_Err:
MsgBox "Error # " & Err.Number & ": " & Err.Description
Resume CloseWord_Exit
End Sub

--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
A

Albert D. Kallal

There is a parameter to the save command in word that will NOT save the
document.

WordDoc.Close (False)

Or,
wordApp.ActiveDocument.Name.Close (false)

On the other hand, you might just want to use my word merge example. It does
what you want,a and a whole lot more. It also easy to use with any existing
application.

check out:

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

Scott

For some reason, your stuff works great with office xp, but not with 2003.
it maybe because i'm running access xp and office 2003 on same pc.

thanks anyway.
 
A

Albert D. Kallal

Gee, I have not yet tried it with 2003, but I see no reason why it should
not work.

However, I have seen the auto creating of the "word" dir fail. Often, just
making the word dir manually fixes this.

I will have to test this...but I don't why it don't work!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top