Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I Print saved SNP files from code?

Status
Not open for further replies.

kchernak

Technical User
May 28, 2002
32
0
0
US
I have an A2K app that generates 100+ individual snapshot reports and saves them to a time/date stamped folder. Later, I need to print these snp reports, but doing it one-at-a-time is killing me. I found some code using the filesystemobject that seems to do everything I need to locate and cycle through the files, but I can't figure out how to print them.

Please anyone have any suggestions? code I hve is below. Thanks!


Dim fsoSysObj As FileSystemObject
Dim fdrFolder As Folder
Dim filFile As File

' Return new FileSystemObject
Set fsoSysObj = New FileSystemObject
Dim strPath, nfiles
strPath = RptFolderNameP 'folder name variable
Set fdrFolder = fsoSysObj.GetFolder(strPath)
nfiles = fdrFolder.Files.Count

' Loop through Files collection
For Each filFile In fdrFolder.Files

If Right(filFile, 3) = "snp" Then

REM here is where I want to print the snp report

End If
Next

 
there might be a better way but this should work.

Dim SnapFile As String, stAppName As String

SnapFile = "C:\test.snp"

stAppName = "C:\Program Files\Common Files\Microsoft Shared\Snapshot Viewer\SNAPVIEW.EXE " & Chr$(34) & SnapFile & Chr$(34)

Call Shell(stAppName, 1)
SendKeys "%" & "f" & "p" & "~"
SendKeys "%" & "f" & "x
 
Found this a while ago that I use to print files from VBA using an API call to ShellExecute:

Code:
Public 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

Public Const SW_HIDE = 0
Public Const WIN_NORMAL = 1         'Open Normal
Public Const WIN_MAX = 2            'Open Maximized
Public Const WIN_MIN = 3            'Open Minimized

Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

To print a file then:
Code:
Call apiShellExecute(Me.hWnd, "Print", sFilePath, "", sFilePath & "\", SW_HIDE)
I'm pretty sure it's courtesy of Dev Ashish, and it uses the default printer but works well.
 
Thanks drctx - I didn't have any luck getting the sendkey statements to work - tried everything. I spent some time looking through the snapview help files and ended up having to create a form with a snapshot control where I could manipulate the snapshot path property using code, and then cycle through the snp files in the folder to print the reports. Not sure its the fastest way to go, but I'm limited by the speed of the printer anyway, and I'm the only user of the application.

Bradles that's for your help as well - I think the api solution is probably easier and cleaner that what I did, but I haven't played with it yet.

Thanks to you both for the help and ideas!
 
Bradles - sorry - noticed as I hit the send button - meant to type 'thanks' for your help - not 'that's' for your help.
 
Hullo Kchernak,
I have now tried two days to change the snapshotpath
on a form to reflect the snp report.
I am at my wits end after searching the snapshot viewer
on the net.
Please place your solution.
It is highly appreciated
Thanks again
Piet
 
Hullo Kchernak,
Sorry I was so driven up the wall that I spoke to you as if you knew all my frustation.
I run AccesXP.
I have created a form with the snapshot viewer and a ref to an existing snp report in another folder, and which on open checks a folder for files. If present I check for snp files and then go over to change the SnapshotPath property the the file just identified.
No luck, it boms out with an error "No Object"
I tried the whole book.(I am clearly a closed book)
I gather from your post that you succeeded.
Please help
Obviously anyone reading this may also solve my problem.
Thanks ever so much.
Piet
 
Romnew--your best bet would be to start a new post. Like me, everyone else probably sees that this post has lots of responses to it and it being answered by someone else...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top