How to print Word Doc or Excel file from Access

  • Thread starter Thread starter SF
  • Start date Start date
S

SF

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
 
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
 
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
 
Thank you Wayne. the code work perfectly...

SF

Wayne-I-M said:
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
 
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....
 
Back
Top