BanyanTech
asked on
Load ListBox or ComboBox with a Specific Folder Directory
I have searched all the answers I could find and none seemed to work me (they either all produced errors or produced empty listboxes)....so clearly I have missed something.
I am using Access 2007
I want to be able to display ALL the files and sub-folders of a specific folder with a listbox (or combobox...whichever is best to use). If sub-folders are displayed, the user should be able to click into the subfolder.
I located coding which starts the listbox with all found directories on the network but I seem unable to modify it to specify a starting point.
I am using Access 2007
I want to be able to display ALL the files and sub-folders of a specific folder with a listbox (or combobox...whichever is best to use). If sub-folders are displayed, the user should be able to click into the subfolder.
I located coding which starts the listbox with all found directories on the network but I seem unable to modify it to specify a starting point.
Private Sub sFillRoot()
Dim strAllDrives As String
Dim strTmp As String, strOut As String
Dim loDir As clsDir
Set loDir = New clsDir
strAllDrives = fGetDrives()
strOut = vbNullString
mboolRoot = True
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives, vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives, vbNullChar) + 1)
strOut = strOut & strTmp & ";"
Loop While strAllDrives <> ""
'trim strOut
strOut = Left$(strOut, Len(strOut) - 1)
' populate the ListBox
With Me!lbxFolders
.RowSourceType = "Value List"
.RowSource = strOut
End With
' this is a back button allowing the user to backup through the folder
Me!cmdNavUp.Enabled = False
Set loDir = Nothing
mstPath = vbNullString
End Sub
ASKER
Thank you Ramanhp
However the code I included in my opening post does everything I want it to do except allow me to specify a starting point.
The code I included starts the browser (which is actually a custom made form) at the very top of the network folders (similar to just clicking on 'My Computer') rather than within say the "C:\" drive only...but it provides me the ability to display all sub-folders (in the current listbox) and all files (in an adjacent listbox) found within along with the ability to select files for importing (if applicable) and/or opening for viewing.
So all I need is the ability to tell the code to start at a specific point...
Example: "C:\Temp\Employees\JohnDoe \"
However the code I included in my opening post does everything I want it to do except allow me to specify a starting point.
The code I included starts the browser (which is actually a custom made form) at the very top of the network folders (similar to just clicking on 'My Computer') rather than within say the "C:\" drive only...but it provides me the ability to display all sub-folders (in the current listbox) and all files (in an adjacent listbox) found within along with the ability to select files for importing (if applicable) and/or opening for viewing.
So all I need is the ability to tell the code to start at a specific point...
Example: "C:\Temp\Employees\JohnDoe
ASKER
Here - I have included a trimmed down version of what I have already....you will be able to see how the listboxes are filled (but none of the button commands will work as I deleted everything but the relevant form and macro's)
Browser.mdb
Browser.mdb
Private Sub Form_Open(Cancel As Integer)
dim YourDesiredPath
YourDesiredPath = "C:\Temp\Employees\JohnDoe \"
Call sFillRoot
Me!lblPath.Caption = YourDesiredPath
'mstFilePath
Call sNavigate(YourDesiredPath)
End Sub
dim YourDesiredPath
YourDesiredPath = "C:\Temp\Employees\JohnDoe
Call sFillRoot
Me!lblPath.Caption = YourDesiredPath
'mstFilePath
Call sNavigate(YourDesiredPath)
End Sub
ASKER
hmm....the Call sNavigate(YourDesiredPath) produces a byRef Argument Type Mismatch error
ASKER
Could I just simply replace...
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives, vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives, vbNullChar) + 1)
strOut = strOut & strTmp & ";"
Loop While strAllDrives <> ""
...with...
strOut = "C:\Temp\Employees\JohnDoe \"
...could I not simply do that? Or am I thinking to simply?
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives, vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives, vbNullChar) + 1)
strOut = strOut & strTmp & ";"
Loop While strAllDrives <> ""
...with...
strOut = "C:\Temp\Employees\JohnDoe
...could I not simply do that? Or am I thinking to simply?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Exactly what I was looking for!
http://www.ammara.com/access_image_faq/file_open_dialog.html
http://www.ammara.com/access_image_faq/browse_for_folder_dialog.html