Avatar of seanlhall
seanlhall
Flag for United States of America asked on

How do I populate a list box with local folder directory .

I have a form the loads a local directory into a listbox. The application works great if the local directory is is set yo CurDir(). I changed it to a local address on my computer. At this point it will load the list box, but if you click any folders that are listed you begin getting errors, like run time error 76 path not found or run time error 91 block not set. I have included a sample file. You would just need to change the local path in the LoadLocalDir() event.  LoadFilelist.accdb
Microsoft Access

Avatar of undefined
Last Comment
seanlhall

8/22/2022 - Mon
als315

I've changed some strings:
If IsNull(Me.txtLocalDir) Then Me.txtLocalDir = "C:\Users\SeanLap\Documents\Project FTP"
in Sub LoadLocalDir
and Sub:
 
Private Sub lstLocalDir_DblClick(Cancel As Integer)

    If Me.lstLocalDir.Column(1, Me.lstLocalDir.ListIndex + 1) = bzftpDir Then
        Me.txtLocalDir = Me.txtLocalDir & "\" & Me.lstLocalDir.Column(0, Me.lstLocalDir.ListIndex + 1)
        ChDir Me.txtLocalDir
        LoadLocalDir
    End If
End Sub

Open in new window

LoadFilelist.accdb
Scott McDaniel (EE MVE )

I changed a few things:

Sub LoadLocalDir()
'On Error GoTo ErrorControl_Click_Err
    Dim db As DAO.Database, rs As DAO.Recordset
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("bzLocalDir")
    db.Execute "delete from bzlocalDir"
    
    'Me.txtLocalDir = CurDir()
    '/Me.txtLocalDir = "C:\Users\SeanLap\Documents\Project FTP"
    
    Dim CTmp As String
    CTmp = Dir(Me.txtLocalDir & "\*", vbDirectory)
    Do While CTmp <> ""
        If CTmp <> "." Then
            rs.AddNew
            rs!FileName = CTmp
            If (GetAttr(Me.txtLocalDir & "\" & CTmp) And vbDirectory) = vbDirectory Then
                rs!Size = bzftpDir
            Else
                rs!Size = Right(Space(12) & FileLen(Me.txtLocalDir & "\" & CTmp) & "", 12)
            End If
            rs.Update
        End If
        CTmp = Dir
    Loop
    
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    
    Me.lstLocalDir.Requery
'ErrorControl_Click_Exit:
  '  Exit Sub
    
'ErrorControl_Click_Err:
'MsgBox Err.Description
 '   Resume ErrorControl_Click_Exit


End Sub

Open in new window


and this:

Private Sub lstLocalDir_DblClick(Cancel As Integer)

    If Me.lstLocalDir.Column(1, Me.lstLocalDir.ListIndex + 1) = bzftpDir Then
        Me.txtLocalDir = Me.txtLocalDir & "\" & Me.lstLocalDir.Column(0, Me.lstLocalDir.ListIndex + 1)
        ChDir Me.txtLocalDir  '/& "\" & Me.lstLocalDir.Column(0, Me.lstLocalDir.ListIndex + 1)
        LoadLocalDir
    End If
End Sub

Open in new window


This seemed to work for me.
ASKER CERTIFIED SOLUTION
Bitsqueezer

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
seanlhall

ASKER
This method work. Thanks.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck