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.

'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

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.

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.

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!