• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4692
  • Last Modified:

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?
0
requisiteSystem
Asked:
requisiteSystem
1 Solution
 
requisiteSystemAuthor Commented:
does anyone have some expertise regarding the common dialog control used in access 2000?
0
 
1WilliamCommented:
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)
        Else
            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.
0
 
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(*.*)"
        .ShowOpen
    End With
    fileName = CommonDialog1.fileName
    MsgBox fileName
   
End Sub
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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.
Jim.
0
 
requisiteSystemAuthor Commented:
Jim,
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.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Let me check.....

Jim.
0
 
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).

Jim.
0
 
requisiteSystemAuthor Commented:
i'm using 2000 developers version...the control is of class MSComDlg.CommonDialog.1...Microsoft Common Dialog Control, version 6.0
0
 
Jim Dettman (Microsoft MVP/ EE MVE)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"
  Me.ActiveXCtl0.ShowOpen
 
  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:

D:\GRAPHICS JIM1.GIF JIMPIC.BMP JIMPIC2.GIF

  Let me know if that works

Jim.
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 .  
0
 
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.

Jim.
0
 
msfraserCommented:
The filename returned from the multiselect explorer type dialog is the path, followed by the selected filenames. These fields are delimited by VbNullChar.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now