Solved

multiselect common dialog control

Posted on 2003-12-10
13
4,677 Views
Last Modified: 2011-04-14
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
Comment
Question by:requisiteSystem
13 Comments
 

Author Comment

by:requisiteSystem
ID: 9937404
does anyone have some expertise regarding the common dialog control used in access 2000?
0
 
LVL 18

Expert Comment

by:1William
ID: 9941355
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
 

Author Comment

by:requisiteSystem
ID: 9941523
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
 
LVL 57
ID: 9941628
<<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
 

Author Comment

by:requisiteSystem
ID: 9941725
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
 
LVL 57
ID: 9941852
Let me check.....

Jim.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 57
ID: 9941867
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
 

Author Comment

by:requisiteSystem
ID: 9941984
i'm using 2000 developers version...the control is of class MSComDlg.CommonDialog.1...Microsoft Common Dialog Control, version 6.0
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 150 total points
ID: 9943385
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
 

Author Comment

by:requisiteSystem
ID: 9944411
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
 
LVL 57
ID: 9944451
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
 

Expert Comment

by:msfraser
ID: 10117787
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now