Link to home
Create AccountLog in
Avatar of seanlhall
seanlhallFlag 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
Avatar of als315
als315
Flag of Russian Federation image

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
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
Avatar of Bitsqueezer
Bitsqueezer
Flag of Germany image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of seanlhall

ASKER

This method work. Thanks.