UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Close Document Via Code?, Any Version    
 
   
fizzy1
post Sep 5 2018, 05:04 PM
Post#1



Posts: 468
Joined: 26-May 11



Hi,

I'm reasonably familiar with VBA in Access but never tried it in Word. I've got some code running fine and simply want to have the Word doc close out as the last step in the process. In Access I would simply use a:

CODE
DoCmd.Quit

but it seems Word doesn't like that. Can someone please point me to the correct code?

(A note about versions, the Version dropdown in the editor here doesn't give me an Office 2016 option (!) but that's nominally where I'm working. I assume this would / should work just as well in O2010 which is my main dev environment.)

Thanks,
Toby.

--------------------

thanks,
fizzy1.
Go to the top of the page
 
fizzy1
post Sep 5 2018, 05:09 PM
Post#2



Posts: 468
Joined: 26-May 11



False alarm, I found it:

CODE
Application.Quit

https://docs.microsoft.com/en-us/office/VBA...on.quit(method)

Apologies for burning a slot.

Toby.

--------------------

thanks,
fizzy1.
Go to the top of the page
 
DanielPineault
post Sep 5 2018, 07:41 PM
Post#3


UtterAccess VIP
Posts: 6,068
Joined: 30-June 11



Have you create a Word Object variable? Such as:

CODE
Set oWord = CreateObject("Word.Application")



Then you'd do something like
CODE
Dim oWord As Object

Set oWord = CreateObject("Word.Application")
oWord.Visible = True 'True=Make Word visible to the user, False=Hide word so the user never see it

  '...the rest of your code

oWord.Quit True 'True=Save changes, False=Do not save changes
If Not oWord  Is Nothing Then Set oWord = Nothing

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
BruceM
post Sep 6 2018, 06:55 AM
Post#4


UtterAccess VIP
Posts: 7,638
Joined: 24-May 10
From: Downeast Maine


Daniel, the OP is trying to close the document from within Word. I believe your code is a way of doing the same action from within Access, or another Office program. The code the OP found will close the entire Word application, but apparently that is the intent.
Go to the top of the page
 
DanielPineault
post Sep 6 2018, 07:00 AM
Post#5


UtterAccess VIP
Posts: 6,068
Joined: 30-June 11



@BruceM - Sorry. You seem to be correct, I missed the category (Word). My Bad.

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
BruceM
post Sep 6 2018, 07:32 AM
Post#6


UtterAccess VIP
Posts: 7,638
Joined: 24-May 10
From: Downeast Maine


Been there, more than once smile.gif
Go to the top of the page
 
fizzy1
post Sep 7 2018, 11:07 AM
Post#7



Posts: 468
Joined: 26-May 11



Thanks all. Yep, the solution I found (my second post) addressed my needs.

--------------------

thanks,
fizzy1.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    23rd September 2018 - 08:41 PM