multiselect common dialog control

i need the ability to select multiple files from a dialog.   i have set the multiselect & explorerType flags of my dialog control.  if i execute and select multiple files from the dialog, i am doing msgbox(fileName),  where fileName = dialog.fileName.  the msgbox returns the path of the files selected.  I need to get both the selected filenames into variables for an eventual import process.  Shed light, anyone?
Who is Participating?
Jim Dettman (Microsoft MVP/ EE MVE)Connect With a Mentor PresidentCommented:
I just tried it here and it works as expected.  Try this:

1. Open a new form.
2. Drop the dialog control unto it.
3. In the forms OnOpen Event do:

  Me.ActiveXCtl0.Flags = cdlOFNAllowMultiselect Or cdlOFNNoLongNames
  Me.ActiveXCtl0.Filter = "Picture Files (*.bmp;*.jpg;*.gif)|*.bmp;*.gif;*.jpg"
  Debug.Print Me.ActiveXCtl0.FileName

 (substitute the correct control name)

  View the form and select a couple of files from the dialog.  Now check the intermediate window.  I got the following:


  Let me know if that works

requisiteSystemAuthor Commented:
does anyone have some expertise regarding the common dialog control used in access 2000?
A couple of thoughts.  Typically, when you have multiple variables, you have two avenues to pursue that will allow you to hold the vaules in one variable.  Either an array or a deliminated string.  You need to be careful when using an array as there is the possibility of a misinterpertation of the comma in a filename that could be read as a break between values.  Therefore, it will be safer to use a string variable seperated by a character that is not usable in a filename (\ / : * ? " < > |).  I would suggest either the colon (:) or pipe(|).

When you loop through the multi select, put in the character:
Dim strMyFileNames as string

    ' Get selected item(s)
    For Each itm In lst1.ItemsSelected   ' Your source, change to suit
        If strMyFileNames  = "" Then
            strMyFileNames = lst1.ItemData(itm)
            strMyFileNames  = strMyFileNames & "| " & lst1.ItemData(itm)        
        End If
    Next itm

Now you have a single variable you can use.  Your next step will be to process the data.  You will want to read the variable, loop through and procee each section between the pipes.

A last suggestion would to not use the common dialog control and instead the api call to use the windows file dialog box.  much more flexible.
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

requisiteSystemAuthor Commented:
i don't understand.  I am dealing with a dialog control with multiselct and explorer flags set.  i'm not sure of the relevance of the "ItemsSelected" property noted in above comment.  I'm dealing with the "fileName" property of a dialog control after user has chosen multiple files.  I need to get the full path of ALL files chosen.  Am I missing something here?  Not sure we are on the same page with your comment.  Here is my code.  Again the dialog control is on a form and it opens when the form opens:

Private Sub Form_Open(Cancel As Integer)
    Dim DelimPos As Long
    Dim NextName As String
On Error GoTo ErrHandler
    fileName = ""
    With CommonDialog1
        .CancelError = True
        .flags =&H80000 + &H200 + &H200000
        .Filter = "All files(*.*)"
    End With
    fileName = CommonDialog1.fileName
    MsgBox fileName
End Sub
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<where fileName = dialog.fileName.  the msgbox returns the path of the files selected.  I need to get both the selected filenames into variables for an eventual import process.  Shed light, anyone? >>

  I've never used the dialog control in multi-select mode,  but still believe I can help.  What your saying is that dialog.filename contains the list of all the files correct?  If so, then you simply need to parse the string.  What deleimtier is used between the items?  Also, what do you want to put these into, an array?  That's just one approach.  I have string handling functions that will return the nth token of a string based on a delimiter, so you really don't even need to do anything with them.

Answer the above and I'll get back to you ASAP.
requisiteSystemAuthor Commented:
Dialog.filename does indeed return a string with the value equal to the full path of the file chosen, including the fileName.  However, when I put the dialog in multi-select mode, and choose a file, then dialog.filename returns the path of the files only, i.e.,  

    a.)  C:\Desktop\file.txt        <------without multiselect
    b.)  C:\Desktop                  <------with multiselect

Documentation on this does say Dialog.filename returns a delimited string when in multiselect mode.  But when i msgbox this value, I only get the path, without indication of the filenames chosen.  

Thx for giving it a go.
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Let me check.....

Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
BTW, version of Access your using and which dialog control is this that were talking about (just want to be sure it's not a 3rd party control).

requisiteSystemAuthor Commented:
i'm using 2000 developers version...the control is of class MSComDlg.CommonDialog.1...Microsoft Common Dialog Control, version 6.0
requisiteSystemAuthor Commented:
Jim, thanks for shedding light on my problem.  For some reason, when I do Msgbox(dialog.filename), it doesn't work.  However, I DO get what i want when i use debug.print(dialog.filename).  Isn't that a b**ch...Thanks for shedding the light .  
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Probably has to do with the length of the returned string or it's termination.  The default is 256 bytes I believe, which shouldn't be a problem for the message box.  Anyway, glad to hear that your on your way.

The filename returned from the multiselect explorer type dialog is the path, followed by the selected filenames. These fields are delimited by VbNullChar.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.