RE: Print all docs in a folder
- From: ND Pard <NDPard@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 5 Feb 2009 15:00:26 -0800
In Access, press the F1 key for Help and look up the DIR function.
You'll find:
Dir returns the first file name that matches pathname. To get any additional
file names that match pathname, call Dir again with no arguments. When no
more file names match, Dir returns a zero-length string (""). Once a
zero-length string is returned, you must specify pathname in subsequent calls
or an error occurs. You can change to a new pathname without retrieving all
of the file names that match the current pathname. However, you can't call
the Dir function recursively. Calling Dir with the vbDirectory attribute does
not continually return subdirectories.
' Returns "WIN.INI" (on Microsoft Windows) if it exists.
MyFile = Dir("C:\WINDOWS\WIN.INI")
' Returns filename with specified extension. If more than one *.ini
' file exists, the first file found is returned.
MyFile = Dir("C:\WINDOWS\*.INI")
' Call Dir again without arguments to return the next *.INI file in the
' same directory.
MyFile = Dir
' Return first *.TXT file with a set hidden attribute.
MyFile = Dir("*.TXT", vbHidden)
' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Debug.Print MyName ' Display entry only if it
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop
Good Luck
"JIM" wrote:
Hi ND, thanks for quick response. That indeed was part of my problem but not.
all. I changed all input to include backslash, thank you. It still does not
work though. The line that is the problem is:
strFile = Dir(strFolder & "*.*")
when I ran in debug strFile contained the proper path until this line then
became = null after line. Can you see some syntax discrepancy?
TIA
"ND Pard" wrote:
Your code does not appear to assure that your me.txtPrintAll.value ends with
a backslash ( \ ). Is it possible that this may be part of your problem.
Example: If the value of me.txtPrintAll.value is: C:\temp
then strFile = Dir(C:\temp*.*)
instead of: strFile = Dir(C:\temp\*.*)
Hope this is of some help.
Good Luck.
"JIM" wrote:
I'm calling a module to print all pdfs in a folder and it's not working. It
works fine in another subroutine that just prints one document but I can't
seem to modify it to print out a folder. Here's my code:
Private Sub Option62_Click() 'This subroutine will print all files in a
folder
Dim strFolder As String
Dim strFile As String
If Not IsNull(Me.txtPrintAll) Then
strFolder = Me.txtPrintAll
strFile = Dir(strFolder & "*.*")
Do While Len(strFile) > 0
Call ExecuteFile(strFolder & strFile, "Print") ' strFolder &
strFile is the full path to the file
strFile = Dir()
Loop
Else
MsgBox "Print All is blank"
End If
End Sub
And here's module:
Option Compare Database
Option Explicit
Public Const SW_Hide = 0
Public Const SW_Minimize = 6
Public Const SW_Restore = 9
Public Const SW_Show = 5
Public Const SW_ShowMazimized = 3
Public Const SW_ShowMinimized = 2
Public Const SW_ShowMinnoActive = 7
Public Const SW_Showna = 8
Public Const SW_ShownoActivate = 4
Public Const SW_ShowNormal = 1
Public Declare Function ShellExecute 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 Sub ExecuteFile(SFileName As String, sAction As String) 'sAction can
be either "Open" or "Print"
Dim vReturn As Long
If ShellExecute(Application.hWndAccessApp, sAction, SFileName,
vbNullString, vbNullString, SW_ShowNormal) < 33 Then
MsgBox "File not found"
End If
End Sub
TIA
- Follow-Ups:
- RE: Print all docs in a folder
- From: JIM
- RE: Print all docs in a folder
- References:
- Print all docs in a folder
- From: JIM
- RE: Print all docs in a folder
- From: ND Pard
- RE: Print all docs in a folder
- From: JIM
- Print all docs in a folder
- Prev by Date: Navigating from form to subform to subform
- Next by Date: Re: change toggle on entry in combobox
- Previous by thread: RE: Print all docs in a folder
- Next by thread: RE: Print all docs in a folder
- Index(es):
Relevant Pages
|