Solved

multiselect common dialog control

Posted on 2003-12-10
13
4,680 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

696 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