Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to print Word Doc or Excel file from Access

77 views
Skip to first unread message

SF

unread,
May 12, 2009, 2:46:14 AM5/12/09
to
Hi,

I have saved the project dicuments (.Doc or .xls) in one of field of a
table. I have created a button where user can print the file but I don't
know how to code.

I have some ideas below

if right(field,3) = "doc" then
print word document base on the select path
else
print excel file
end if

Couls someone advice please.

SF


Wayne-I-M

unread,
May 12, 2009, 3:37:01 AM5/12/09
to
Hi

There's a few mehtods - this is just one.

Create a new module

Function PrintDoc()
Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open "Add path to Doc here"
WordObj.PrintOut Background:=False
WordObj.Quit
Set WordObj = Nothing
End Function

'Change Add path to DOC here to the real path to the DOC'

On a form add a button. Put this OnClick

Private Sub ButtonName_Click()
Call PrintDoc
End Sub

'Change ButtonName to what is really is'

OIf course in your case you would add this to the "if" - something like this

if right(field,3) = "doc" then

Call PrintDoc
else
Call PrintExcel
end if

Do the same for the excel file (but change wordobj and createobject)

Not sure what you mean by right(field,3) but you must ??


HtH

--
Wayne
Manchester, England.

Wayne-I-M

unread,
May 12, 2009, 3:39:01 AM5/12/09
to
ooops just though - and reread ??

As you have a number of paths you will need to declare the path as a
variable - link this (DIM) to your table field / form control

--
Wayne
Manchester, England.

SF

unread,
May 12, 2009, 5:44:20 AM5/12/09
to
Thank you Wayne. the code work perfectly...

SF

"Wayne-I-M" <Way...@discussions.microsoft.com> wrote in message
news:7FAEFAC7-B63B-425E...@microsoft.com...

Albert D. Kallal

unread,
May 12, 2009, 12:58:52 PM5/12/09
to
To print a word, excel, or even a pdf, you can use:


dim strDoc as string

strdoc = "some path name to doc, excel, or even pdf)

Then:

CreateObject("Shell.Application").Namespace(0).ParseName(strDoc).InvokeVerb
("&Print")

In fact, the above works pretty much with any file + application that
supports right clicking on the file and choosing print....


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOO...@msn.com


SF

unread,
May 12, 2009, 8:41:48 PM5/12/09
to
Thank. This is the first "shell" that i have seen for the first time. Will
try it.

SF

"Albert D. Kallal" <PleaseNOOO...@msn.com> wrote in message
news:O0IbvLy0...@TK2MSFTNGP03.phx.gbl...

0 new messages