Browsing for multiple files

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

I've got an Access form which has a field which stores a
user-selected set of files from a specific directory (ie
just the file names, not the directory; that's in a
different field).

I've tried the suggested API file browsing function, but
that only works for one file (and returns the full path). I
tried changing it, and managed to get the user to be able
to select multiple files, but it then just returned the
directory path instead of the file(s).

Anyone ? Please ? Need help !
Thanks.
 
Simon said:
I've got an Access form which has a field which stores a
user-selected set of files from a specific directory (ie
just the file names, not the directory; that's in a
different field).

I've tried the suggested API file browsing function, but
that only works for one file (and returns the full path). I
tried changing it, and managed to get the user to be able
to select multiple files, but it then just returned the
directory path instead of the file(s).

Anyone ? Please ? Need help !
Thanks.

IIRC, when you set that up to select multiple files, the list comes back
as a null-delimited list, structured like this:

folder path + Chr(0) + filename1 + Chr(0) + filename2 ...

The commonly posted ahtCommonFileOpenSave function uses a TrimNull
function that truncates the value returned from the API call at the
first Chr(0) character, and so cuts off the file names. What I have
done is remove that call to TrimNull from the ahtCommonFileOpenSave
function and leave it to the calling routine to parse out the list. In
the case where I call it for multi-select, I truncate the string at the
first occurrence of *two* Chr(0) characters in a row. For example, a
function named "fncGetPayrollImportFiles" uses this logic:

lngFlags = ahtOFN_FILEMUSTEXIST Or _
ahtOFN_ALLOWMULTISELECT Or _
ahtOFN_NOCHANGEDIR Or _
ahtOFN_LONGNAMES Or _
ahtOFN_EXPLORER Or _
ahtOFN_HIDEREADONLY Or _
0

' ... set up other arguments ...

varFileName = ahtCommonFileOpenSave( _
OpenFile:=True, _
InitialDir:=strDirectory, _
Filter:=strFilter, _
Flags:=lngFlags, _
hWnd:=Forms!frmFileDialog.hWnd, _
DialogTitle:="Choose Payroll File(s) to Import")

' Because we allow multi-select, the value returned by the dialog
' (if not null) will consist of multiple items separated by null
' characters. The first item will be the folder path, followed by
' the first file, then the second file (if any), etc.

If Len(varFileName & "") = 0 Then
fncGetPayrollImportFiles = ""
Else
intPos = InStr(varFileName, String(2, vbNullChar))
If intPos > 0 Then varFileName = Left(varFileName, intPos - 1)
fncGetPayrollImportFiles = varFileName
End If

Then I split the result using vbNullChar as a delimiter. Note that if
only one file was selected, the whole path and file name are returned in
the first list item.
 
many thanks; that's just the jobby I needed.

Thanks very much indeed for explaining the technical
ins+outs of the arguments and return values; that's helped
me out enormously.

I'm always very surprised and pleased by the kind of
response I get from this forum; everyone seems to genuinely
want to help out their fellow techies, and it's very much
appreciated.

Big cheers.
Simon.
 
Back
Top