Running A Word Macro From Access Command Button

Ploho

New member
Local time
Today, 17:23
Joined
Aug 16, 2009
Messages
6
Hi,

Version (Access): 2003
Version (Word): 2003

Wanted to know if it is possible to run a word macro from a button on my access form that opens the word document.

I have got this code currently (on the access form) - i can open the document correctly by using this code:

Private Sub IWS_Print_Button_Click()
On Error GoTo Err_IWS_Print_Button__Click
Dim objword As Object
Set objword = CreateObject("Word.Application")
objword.Visible = True
objword.Documents.Open ("C:\Documents and Settings\Neil\My Documents\sad.doc")
Exit_IWS_Print_Button__Click:
Exit Sub
Err_IWS_Print_Button__Click:
MsgBox Err.Description, , "User Request"
Resume Exit_IWS_Print_Button__Click
End Sub

However, i want to be able to run the word macro code (shown below) automatically after opening the document, in order to print it - unless there is some code that already enables me to do this that i have missed.

Could all you brill people help by telling me where the code should go and any extra lines that i need to add to the above code.

This is the macro code that i want to run upon opening the document:

Sub Printing()
'
' Printing Macro
' Macro recorded 31/08/2009 by Neil
'
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=False, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
 
I may be wrong, but I don't believe you can do this via Access.

Couldn't you just place your code in the Document_Open event handler?
 
Couldn't you just place your code in the Document_Open event handler?

Hello, i can't seem to find the Document_Open event handler - where is this in the form? :D
 
Not the access form....dbDamo is referring to the word document.
 
Yes I was referring to the Word Doc's Document_Open event handler, should have been clearer, my apologies!!

If you can get your macro to run when the document opens then all your button on your Access form has to do is run a RunApp macro to open the required Word Doc.
 
Hi Guys,

Thanks for the information, however, after surfing the internet for more information - i have found a way of doing it all from Access.

I am now simply using this in the OnClick Event of the form, the only item that needs changing is the filepath in the red, so long as the button is called "IWS_Print_Button" (without quotation marks):

Private Sub IWS_Print_Button_Click()
On Error GoTo Err_IWS_Print_Button__Click
Dim objword As Object
Set objword = CreateObject("Word.Application")
objword.Visible = True
objword.Documents.Open ("C:\Filepath\DocumentName.doc")
objword.Application.Options.PrintBackground = False
objword.Application.ActiveDocument.PrintOut
Exit Sub
Err_IWS_Print_Button__Click:
MsgBox Err.Description, , "User Request"
End Sub
 
Wow, that'll teach me to learn to read the whole post before I comment!!

I was concentrating on the title, "running a word macro from access command button", I didn't realise all you wanted to do was print the document!!!
 

Users who are viewing this thread

Back
Top Bottom