CMDialog - File open - Multiple file selection order.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mark2802
    New Member
    • Jul 2006
    • 3

    CMDialog - File open - Multiple file selection order.

    When using CMdialog control to open multiple filenames is there a way to force the order in whch the resulting filenames are returned? I require the filenames to be returned in the order they were picked. ie holding down the control key and clicking on each file. However something appears to sort the returned filenames into another order which I've yet to work out.

    This is the code I'm using:
    Code:
    CMDialog.FileName = ""nothing
        CMDialog.DialogTitle = "Select photo/s..."
        CMDialog.Filter = "jpg|*.jpg"
        CMDialog.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNHideReadOnly
        CMDialog.InitDir = "C:\Documents and Settings\Myuser\My Documents\My Pictures\somefolder"
        CMDialog.MaxFileSize = 32000 
        CMDialog.ShowOpen                   'opens fileopen
        strInputFileName = CMDialog.FileName
    strInputFileNam e returns the filenames in a different order to the order in whcih they were selected.

    Any advice most welcomed, thanks Mark
    Last edited by zmbd; Sep 6 '12, 04:12 AM. Reason: (Z)inserted required code tags
  • PEB
    Recognized Expert Top Contributor
    • Aug 2006
    • 1418

    #2
    Code:
    Sub Main()
    
        'Declare a variable as a FileDialog object.
        Dim fd As FileDialog
    
        'Create a FileDialog object as a File Picker dialog box.
        Set fd = Application.FileDialog(msoFileDialogFilePicker)
    
        'Declare a variable to contain the path
        'of each selected item. Even though the path is a String,
        'the variable must be a Variant because For Each...Next
        'routines only work with Variants and Objects.
        Dim vrtSelectedItem As Variant
    
        'Use a With...End With block to reference the FileDialog object.
        With fd
    
            'Use the Show method to display the File Picker dialog box and return the user's action.
            'The user pressed the action button.
            If .Show = -1 Then
    
                'Step through each string in the FileDialogSelectedItems collection.
                For Each vrtSelectedItem In .SelectedItems
    
                    'vrtSelectedItem is a String that contains the path of each selected item.
                    'You can use any file I/O functions that you want to work with this path.
                    'This example simply displays the path in a message box.
                    MsgBox "The path is: " & vrtSelectedItem
    
                Next vrtSelectedItem
            'The user pressed Cancel.
            Else
            End If
        End With
    
        'Set the object variable to Nothing.
        Set fd = Nothing
    
    End Sub
    Last edited by zmbd; Sep 6 '12, 04:13 AM. Reason: (Z)inserted required code tags

    Comment

    • PEB
      Recognized Expert Top Contributor
      • Aug 2006
      • 1418

      #3
      Pardon!
      A little explication!

      In order to display a file dialog box using the FileDialog object, you must use the Show method. Once a dialog box is displayed, no code will execute until the user dismisses the dialog box. The following example creates and displays a File Picker dialog box and then displays each selected file in a message box.

      Comment

      • mady1380
        New Member
        • Sep 2006
        • 18

        #4
        hi

        sory but can you please tell me do i have to declare something else to use Filedialog object

        i am not able to create object dim fd as FileDialog coz i dont have FileDialog.

        i am sorry i am a begginer please help me
        thanks
        Last edited by zmbd; Sep 6 '12, 04:14 AM. Reason: (Z)Removed quoted code. A single line... OK, the entire code block... too much.

        Comment

        • PEB
          Recognized Expert Top Contributor
          • Aug 2006
          • 1418

          #5
          No no, just try this code...

          It should work with the decl=ared References in Access..


          :)

          Comment

          • SammyB
            Recognized Expert Contributor
            • Mar 2007
            • 807

            #6
            PEB, the original question specified that the files be returned in the order that they were picked. I cannot see anyway to use FileDialog to get the files in order. Try both shift-click and control-click, you will see that they are not in the order that they were selected. I would be ecstatic with any solution that returns the order. I cannot do it even with a custom class wrapper around GetOpenFilename . If you have any suggestions, please reply back. TIA --Sam

            Comment

            • DougM
              New Member
              • Oct 2007
              • 1

              #7
              Hi,

              I realise this is quite an old thread, but has anyone figured out how to do this yet. Its most annoying that the FileDialog does not return the selected items in the same order that they were selected.

              Cheers
              Doug

              Comment

              • SammyB
                Recognized Expert Contributor
                • Mar 2007
                • 807

                #8
                Originally posted by DougM
                Hi,

                I realise this is quite an old thread, but has anyone figured out how to do this yet. Its most annoying that the FileDialog does not return the selected items in the same order that they were selected.

                Cheers
                Doug
                This is amazing. I'm bleary-eyed trying to solve this annoyance and you ask the same question. I will soon publish the solution in an Article here, but if you're in a hurry & like challenges, the key is here. I'll post a link here when I complete the module.

                Comment

                Working...