Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    total files in a directory (2003)

    Hi, I am using access to move and manipulate many .doc files, I did have a script in VBA Word but have now decided to move it to VBA Access and make a GUI for it.

    I just have one slight problem, can anyone tell me why I can't select multiply directories to add at once. I had thought I had used the right code for multiselect

    Once I select the direcotries they are nw added to a List box called 'ListBox1' is there a way of counting the files inside the selected directory's. There is likely to be more than one directory in the list box at a time.

    Heres the code som far.

    Many thanks

    Private Sub cmdAddSource_Click()
    Dim strSource(19) As String
    Dim intCount As Integer

    On cmdAddSource_Error GoTo Err_Handler

    'Sets a counter for the array
    For intCount = 0 To 19

    'Message box warning if maximum directory limit is reach
    If ListBox1.ListCount = "20" Then
    MsgBox "Maximum number of source directories has been added!", vbInformation, _
    "Maximum limit reached"
    GoTo ExitHandler
    Else
    End If

    'Open the MS File Dialog Folder Picker to select soure files
    'Adds to end of directory if not already there
    With Application.FileDialog(msoFileDialogFolderPicker)
    .InitialView = msoFileDialogViewProperties
    .ButtonName = "Add source"
    .Title = "Select your source directories"
    If .Show = True Then
    .AllowMultiSelect = True
    'Sets the source director and adds it the the list box on the form
    strSource(intCount) = .SelectedItems(1)
    If Not Right(strSource(intCount), 1) = "" Then
    strSource(intCount) = strSource(intCount) & ""
    ListBox1.AddItem (strSource(intCount))
    If ListBox1.ListCount <= "20" Then
    'Ask if you want to add more directory's
    If MsgBox("Add another source directory?", vbYesNo, _
    "Add more directory's") = vbNo Then
    GoTo ExitHandler
    Else
    End If
    Else
    End If
    End If
    Else
    End If
    End With
    Next

    ExitHandler:
    Exit Sub

    Err_Handler:
    MsgBox "Error running script", vbExclamation

    End Sub
    count
    Regards
    Gerbil (AKA Kevin)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: total files in a directory (2003)

    AllowMultiSelect = True only works if you call FileDialog to select files, i.e. with argument msoFileDialogFilePicker or msoFileDialogOpen, not with msoFileDialogFolderPicker.

    BTW 1, even if it had been possible, you'd have had to set up the code differently: you specify AllowMultiSelect = True after displaying the dialog using Show. That won't have any effect of course, you should have specified it before displaying the dialog.

    BTW 2: there is nothing specific to Access in your question, it is general VBA, so I'll move this thread to the VBA forum.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: total files in a directory (2003)

    If you want to work with folders and files in code, you may want to investigate the FileSystemObject in the Script Runtime library. You make this available by ticking the check box for Microsoft Scripting Runtine in Tools | Options... in the Visual Basic Editor.
    The reference to Script Runtime is stored in the active database or document you're working with.
    Warning: on some corporate networks, scripting is disabled for security reasons; test whether you're able to use it before starting to write code on a large scale.

    Microsoft's reference material can be found in Script Runtime.

    A tutorial with useful examples can be found in TechBookReport FileSystemObject Tutorial.

  4. #4
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: total files in a directory (2003)

    Thanks Hans.

    I have almost moved all the files over, its not perfect but I'd say about 98% went OK, problem is some people were putting a letter after the 6 digit CRN number when the file already exsited! Or worse letters infront of the file name. We have had to rename them all manually!

    Thanks for your help.
    Regards
    Gerbil (AKA Kevin)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •