Solved

multiselect common dialog control

Posted on 2003-12-10
13
4,674 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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

758 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

20 Experts available now in Live!

Get 1:1 Help Now