Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / March 2005

Tip: Looking for answers? Try searching our database.

Open File API call - multiple selections

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FBxiii - 01 Mar 2005 11:39 GMT
Hi,

Using the API call to open the 'Select File' box, is it possible to accept
multiple file selections?

Cheers,
Steve,
Douglas J. Steele - 01 Mar 2005 23:01 GMT
Referring to the code in http://www.mvps.org/access/api/api0001.htm, first
you need to ensure that the Flag parameter includes the value specified by
ahtOFN_ALLOWMULTISELECT, something like:

lngFlags = ahtOFN_FILEMUSTEXIST Or _
               ahtOFN_HIDEREADONLY Or _
               ahtOFN_NOCHANGEDIR Or _
               ahtOFN_ALLOWMULTISELECT

Once you've done that, the value passed back will consist of the folder
name, followed by a null character (Chr$(0)), followed by the name of the
first file selected, followed by a null character, followed by the name of
the second file selected, followed by a null character, and so on until the
last file. There will be two null characters at the end of the string.

Because of the null characters, you can't use the TrimNull function that's
included in the given sample.  Instead, take off the last two characters:

   ahtCommonFileOpenSave = Left$(OFN.strFile, Len(OFN.strFile)-2)

Then use the Split function to break the string into its component parts:

  strInputFileName = ahtCommonFileOpenSave( _
               Filter:=strFilter, OpenFile:=True, _
               DialogTitle:="Please select an input file...", _
               Flags:=ahtOFN_HIDEREADONLY) str

  varFiles = Split(strInputFileName, Chr$(0))
  strFolder = varFiles(0)
  For intLoop = 1 to UBound(varFiles)
     Debug.Print strFolder & "\" & varFiles(intLoop)
  Next intLoop

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Hi,
>
[quoted text clipped - 3 lines]
> Cheers,
> Steve,
FBxiii - 02 Mar 2005 10:13 GMT
Thanks for the reply.

I have had a try but cannot seem to get it to work.

Could you explain where I need to include the Flag Parameter please?

I have tried adding it the GetOpenFile Function in the lngFlags section.

Then I pasted the Split function into a new function and ran it.  I got
presented with a 'funny' OpenFile dialog with a Directory 'Tree' on the right
hand side!

Cheers,
Steve.

> Referring to the code in http://www.mvps.org/access/api/api0001.htm, first
> you need to ensure that the Flag parameter includes the value specified by
[quoted text clipped - 36 lines]
> > Cheers,
> > Steve,
Douglas J. Steele - 02 Mar 2005 23:31 GMT
Sorry: can you post your actual code here?

I just tested the following (which assumes you're using the code from
http://www.mvps.org/access/api/api0001.htm)

Sub djsTest()
Dim intLoop As Integer
Dim lngFlags As Long
Dim strFile As String
Dim strFolder As String
Dim strFilter As String
Dim strOutput As String
Dim varFiles As Variant

   lngFlags = ahtOFN_FILEMUSTEXIST Or _
       ahtOFN_HIDEREADONLY Or _
       ahtOFN_NOCHANGEDIR Or _
       ahtOFN_EXPLORER Or _
       ahtOFN_ALLOWMULTISELECT
   strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _
                   "*.MDA;*.MDB")
   strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
   strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
   strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
   strFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
       Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
       DialogTitle:="Hello! Open Me!")

   If Len(strFile) > 0 Then
       strOutput = "You selected:" & vbCrLf
       varFiles = Split(strFile, Chr$(0))
       If UBound(varFiles) > 1 Then
           strFolder = varFiles(0)
           For intLoop = 1 To UBound(varFiles)
               strOutput = strOutput & strFolder & varFiles(intLoop) &
vbCrLf
           Next intLoop
       Else
           strOutput = strOutput & varFiles(0)
       End If
   Else
       strOutput = "You didn't select anything"
   End If
   MsgBox strOutput

End Sub

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Thanks for the reply.
>
[quoted text clipped - 58 lines]
>> > Cheers,
>> > Steve,
FBxiii - 03 Mar 2005 12:13 GMT
I did get the code from the api0001.htm page.

I didnt realise where the lngFlags =..... part went.

I have tested it, but when I select more than 1 file, the Msgbox only says:
You Selected C:\.  If I select only 1 file, it will show the path and
filename.

Any ideas?

Cheers,
Steve

> Sorry: can you post your actual code here?
>
[quoted text clipped - 105 lines]
> >> > Cheers,
> >> > Steve,
Norman Goetz - 03 Mar 2005 18:22 GMT
Dear Steve
change the TrimNull-Function as seen here:

>I have tested it, but when I select more than 1 file, the Msgbox only says:
>You Selected C:\.  If I select only 1 file, it will show the path and
>filename.
>
>Any ideas?

Private Function TrimNull(ByVal strItem As String) As String
Dim intPos As Integer
   intPos = InStr(strItem, vbNullChar & vbNullChar)
   If intPos > 0 Then
       TrimNull = Left(strItem, intPos - 1)
   Else
       TrimNull = strItem
   End If
End Function

and change the djsTest-Function

Dim strFile As Variant 'String

hth

Norman Goetz

Norman Götz
Douglas J. Steele - 04 Mar 2005 00:12 GMT
> Dear Steve
> change the TrimNull-Function as seen here:
[quoted text clipped - 19 lines]
>
> Dim strFile As Variant 'String

There's no reason to change strFile to a variant: it works fine as a string.
And yes, your revised TrimNull function is probably safer than what I'd
recommended (simply removing the last 2 characters)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

FBxiii - 04 Mar 2005 10:49 GMT
Norman/Douglas,

That works now cheers.  

As a general question, if using a variant as an array, do you not need to
specify how many 'items' the array can hold?  I was trying to use an array
where the maximum number of items was unknown but couldnt figure it out....

Cheers,
Steve.

> > Dear Steve
> > change the TrimNull-Function as seen here:
[quoted text clipped - 23 lines]
> And yes, your revised TrimNull function is probably safer than what I'd
> recommended (simply removing the last 2 characters)
FBxiii - 04 Mar 2005 11:59 GMT
OK,  I have it working by calling a function and passing the Initial Dir and
Title to it.

In the old version I use to use, the function was pass the file name back to
the calling procedure.  How do I pass the varFiles Array back to the calling
procedure?

I get an error 13 when I try GetFileNames = varFiles or an error 9 when I
try GetFileNames = varFiles()

Any ideas?

Cheers,
Steve.

> Hi,
>
[quoted text clipped - 3 lines]
> Cheers,
> Steve,
Douglas J. Steele - 04 Mar 2005 22:31 GMT
I always pass back what the routine found as a string, and parse it in the
calling routine (or, more accurately, by passing what the function returned
to another routine that parses it).

Without seeing your actual code, I'm afraid I can't offer any suggestions.
If you're using the code from http://www.mvps.org/access/api/api0001.htm, I
don't see a GetFileNames anywhere on that page.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> OK,  I have it working by calling a function and passing the Initial Dir
> and
[quoted text clipped - 22 lines]
>> Cheers,
>> Steve,
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.