[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 503
  • Last Modified:

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.
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

Open in new window

0
BanyanTech
Asked:
BanyanTech
  • 5
  • 3
1 Solution
 
BanyanTechAuthor Commented:
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\"
0
 
BanyanTechAuthor Commented:
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
RamanhpCommented:
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
0
 
BanyanTechAuthor Commented:
hmm....the Call sNavigate(YourDesiredPath) produces a byRef Argument Type Mismatch error
0
 
BanyanTechAuthor Commented:
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?
0
 
RamanhpCommented:
oh sorry, just a minor change, i copied the old code by mistake


Private Sub Form_Open(Cancel As Integer)
    Dim YourDesiredPath As String
    YourDesiredPath = "C:\Temp\Employees\JohnDoe\"
    Call sFillRoot
    Me!lblPath.Caption = YourDesiredPath
    Call sNavigate(YourDesiredPath)
End Sub
0
 
BanyanTechAuthor Commented:
Exactly what I was looking for!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now