Hi, Gentlemen!
I am sorry in advance for a long intro.
I am not very familiar with VBA and would greatly appreciate if anyone
could assist me anyhow in solving the following problem.
I need to open and print *.tif image files from MS Access form (using
of other image file type is possible if it does the job).
The task is to print a number of images complementing each other and
referring to a record, on a click of a button. I decided to use
tif-image-type as this is the only image type I know of that can store
more than one image in one file (I could have used a corresponding
folder to store images of one record in, but I do not know how to
programmatically create a folder with a particular name for each
record, and folder-method is not preferred).
I have a code that ideally should work for the type of operation I
need, but it does not work the way it should. I will list the code
below and explain what I have tried to resolve the problem.
If anyone has any ideas on this issue - I would really appreciate any
help or any suggestions.
The code:
Option Compare Database
Private Declare Function apiShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Sub PrintImage_Click()
Dim a As Variant
a = Me!StockNumber
Call apiShellExecute(hWndAccessApp, "Print", _
"C:\" & a & ".tif", 0&, 0&, 1)
End Sub
So far I've tried to print into the following programs: Microsoft
Office Document Imaging, Windows Picture and Fax Viewer, Microsoft
Photo Editor, Lexmark Photo Editor. Some of the mentioned programs
opened the files but just did not print and some did not even open even
though all of them open and print fine through direct use.
I also tried to add or edit system actions and application references
in "Edit file type" window of windows file association menu (for
example, MS Office Document Imaging did not have "print" action
assigned therefore it did not react to "print" command from
"ShellExecuteA", but after I added the action the program returned
a critical error).
But nothing worked so far.
If anyone knows of any replacement for "ShellExecuteA" or have any
ideas on how to resolve an issue - please help!
Thank you!
Peter the grate - 11 Nov 2006 12:10 GMT
There is a VBA equivalent to the APIShell its called "shell"
I tested it with this subroutine - it should be easy enough to mod for your
app. Though I am left wondering why on earth you need to print TIFF files.
Const kApp = "c:\program files\common files\microsoft
shared\modi\11.0\MSPVIEW.EXE"
Const kDataFolder = "c:\Documents and Settings\Peter\My
Documents\Access\Scanned\"
Sub Test(sFile As String)
Dim sCmdLine As String
sCmdLine = """" & kApp & """ /p """ & kDataFolder & sFile & ".tif"""
Shell sCmdLine, vbNormalFocus
End Sub
the command line sCmdLine calls the MSOffice application MSPVIEW which is in
the folder 11.0 when you have office 2003 (ie 11.0) installed.
you need to explicitly nominate the directory location - hence the need for
the enclosing quotes as some folder names have spaces in them.
my scanned files (tiff) are stored in the directory nominated by kDataFolder
MSPVIEW uses a /p command line switch to make it print the file on the
curent printer. (you can find this in the registry). Hope you understand all
the quotes (see access help for details)
Peter...
Another alternative is to store the Tiff files in an OLE object within the
database then use OLE commands to print or display the object. though this
can be a bit of an overkill as the database gets large very fast.
> Hi, Gentlemen!
> I am sorry in advance for a long intro.
[quoted text clipped - 47 lines]
> ideas on how to resolve an issue - please help!
> Thank you!