We help IT Professionals succeed at work.

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

seanlhall
seanlhall used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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 )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:
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.
Hi,

the easiest way is to let the original CurDir where it is and change the Form Load event:

Private Sub Form_Load()

    Set oFtp = New bzFtp
    Me.txtPort = 21
    Me.txtLocalDir = "C:\Users\SeanLap\Documents\Project FTP"
    ChDir Me.txtLocalDir
    LoadLocalDir
    LoadRemoteDir True
End Sub

Open in new window


Please remember that the "CurDir" version only works with the current drive letter in this way. If you want to change the drive you must insert a new control which lists the drive letters and insert the chosen drive letter into the CurDir function.

Cheers,

Christian

Author

Commented:
This method work. Thanks.