Printing a word document within Access

D

DB

My VB program currently exports records from a database into a txt file, then
loads word and we manually use the print button to print the data. I want to
export the records and also get access to print the word document.
 
J

Jack Leach

Go to http://mvps.org/access and find the APIs page (or search page) and
locate the ShellExecute API. This opens a document by default. I believe
the second argument to this can be set to print a document. It will
automatically open the document, print it to the default printer (or last
printer used depending on the app), and close the document.

Post back if you need a hand setting this up.

VBA has a Shell() function, so you may be able to use that instead of the
API. Check the help file and see if there's an argument to print rather than
open.

hth

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
D

DB

I currently use the Shell option, I did try the ShellExecute option, but
still don't know how to get to automatically print and close.
 
J

Jack Leach

I use my own wrapper for the shell execute function, but apparently you can
pass the second argument as "Print"

Public Function dsShell(aFile As String, Optional aPrint As Boolean = False)
If aPrint = False Then
ShellExecute 0, vbNullString, aFile, vbNullString, vbNullString,
vbNormalFocus
Else
ShellExecute 0, "Print", aFile, vbNullString, vbNullString, vbNormalFocus
End If
End Function

hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
D

DB

Works like a dream, thank you

Jack Leach said:
I use my own wrapper for the shell execute function, but apparently you can
pass the second argument as "Print"

Public Function dsShell(aFile As String, Optional aPrint As Boolean = False)
If aPrint = False Then
ShellExecute 0, vbNullString, aFile, vbNullString, vbNullString,
vbNormalFocus
Else
ShellExecute 0, "Print", aFile, vbNullString, vbNullString, vbNormalFocus
End If
End Function

hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 

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