GetMultipleFiles Function

J

John G

Using Access 2003 on Windows XP.
I am using the functions found at :
http://groups.google.com/group/microsoft.public.access.modulesdaovba/msg/59405535b47dc0d7
to select multiple files for an array in a procedure to zip the selected
files. I made the revisions to the above codes that Doug Steele recommended
12/27/07 in his answer to the posted question "File Dialog using API". I
added the few lines Tom Wickerath added to print the file names in the
Immediate Window. When I run the GetMultipleFiles function the printed
results leave out the last "\" between the folder name and the file name.
Prints this:

0 C:\Program Files\OGG\ReportsCommodities.SNP
1 C:\Program Files\OGG\ReportsLand.SNP
2

Should print the two above file names like this

0 C:\Program Files\OGG\Reports\Commodities.SNP
1 C:\Program Files\OGG\Reports\Land.SNP
2

shouldn't it?

Here is the function as I have it.

Public Function GetMultipleFiles(ByVal strExtension As String, strTitle As
String) As Variant


'Purpose: Get list of files of a single type to open from user
'Inputs: strExtension - filetype required
' strTitle - dialog title
'Output: variant array of full path file names selected by user
' or Null if none selected


Dim varReturned As Variant
Dim varFiles As Variant 'variant array to hold result of
dialog
Dim strfilter As String 'for use in dialog
Dim lngFlags As Long 'ditto
Dim intFileCount As Integer 'how many files were selected
Dim strArrFiles() As String 'to work with file array
Dim intI As Integer 'counter
Dim strDirectory As String 'to determine full path
Dim intPosStart As Integer 'counters in parsing of file name
string
Dim intPosEnd As Integer


'set constants
lngFlags = dhOFN_OPENEXISTING Or OFN_ALLOWMULTISELECT Or OFN_EXPLORER
strfilter = strExtension & " Files (*." & strExtension & ")" &
vbNullChar & "*." & _
strExtension & vbNullChar & vbNullChar


'get list of files

varFiles = dhFileDialog(strDialogTitle:=strTitle, strfilter:=strfilter,
lngFlags:=lngFlags)
'if no file sselected then return null and exit

If IsNull(varFiles) = True Then
GetMultipleFiles = Null
Else
varFiles = drRightTrimNull(varFiles)

' Split what was returned into an array
varReturned = Split(varFiles, vbNullChar)

' Determine the number of files we're dealing with.
intFileCount = UBound(varReturned) - LBound(varReturned) + 1
' If just 1 file then simple assignment
If intFileCount = 1 Then
ReDim strArrFiles(0)
strArrFiles(0) = drRightTrimNull(Trim(varFiles))
Else
' Redim an array of filenames
ReDim strArrFiles(intFileCount - 1)

' Populate the array of file names

For intI = 1 To (intFileCount - 1)
strArrFiles(intI - 1) = varReturned(0) & varReturned(intI)
Next intI
' For intI = 1 To intFileCount
' strArrFiles(intI - 1) = varReturned(0) & varReturned(intI - 1)
' Next intI
End If
GetMultipleFiles = strArrFiles

'Print results to Immediate Window
For intI = LBound(strArrFiles) To UBound(strArrFiles)
Debug.Print intI, strArrFiles(intI)
Next intI

End If

End Function

What do I need to do to return the desired results?
Thanks in advance for your help.
John G
 
D

Douglas J. Steele

For intI = 1 To (intFileCount - 1)
strArrFiles(intI - 1) = varReturned(0) & "\" & varReturned(intI)
Next intI
 
J

John G

Thank you for your help, Doug. It now prints the proper path and file name.
John
 

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