Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drive Listbox

Status
Not open for further replies.

Kocheace

Vendor
Oct 31, 2002
97
US
Does VBA support the Drive & File Listbox controls? IT Professional
 
I don't think so. You can get round it using the dialoguebox control or Application.GetOpenFilename.

Or you can write your own Drive & File Listbox controls.
 
I wanted to use the Drive and File listboxes just to get the path of files on the network . Right now I'm using an inputbox for the user to type the path but they seem to have difficulty inputting the correct path.

How would I be able to make my own Drive & File listboxes with Icons(Just to make it more user friendly).
IT Professional
 
If you just want the full path, can you not use the dialogue box control?
You will need to add it thru additional controls: Microsoft Common Dialogue Control

Then:
CommonDialog1.ShowOpen
mypath = CommonDialog1.Filename

Will give the user the standard dialog box to select the file. When they click OK the path is placed into mypath.

To write your own drive and file listbox you would need to check for the drives available, and to be honest, I don't know how to do that one without just trying all possibilities and errortrapping the ones that fail along the lines of:

on error goto oops
for n = 66 to 90 'ascii codes for A-Z
drivename = asc(n)+ ":"
chdir(drivename)
cmbDrives.additem (drivename)
backhere:
next n

oops:
drivename = ""
resume backhere

There is probably an easier, more elegant and faster way, but I don't know it.

To list folders and files, you'll need to list all the folders in a drive and list them in the combo box. Do the same for all the files in the current folder. On double clicking the foldername in the combo box, you'll need to list all the folders and files within that subfolder.

I could write the code, but I'd hate to do that to find your happy with the dialog box. If you do need more, I'll do it.
 
Here's the code I used to get the path of the files and get rid of the filename at the end of the path.

CommonDialog1.ShowOpen
filepath = CommonDialog1.Filename
strpos = instrrev(filepath,"\")
mypath = left(filepath,strpos - 1)


Thanks kylua
IT Professional
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top