Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Directory Files
Doug Henderson 
    
4 years ago
I need to populate a listbox with filenames from a work network directory. Is this possible with VBA?
Scott Axton  @Reply  
        
4 years ago
Yes.  Covered in Access Developer 31.

I don't recommend jumping in in the middle though.  The courses are meant to follow in order so you have the prerequisites for that course.  I don't know what your experience level is with VBA.
Kevin Yip  @Reply  
     
4 years ago
To answer your question, it is possible with VBA, with the Dir() function to read file names from a folder.
Doug Henderson OP  @Reply  
    
4 years ago
Checked out Developer 31. Got the file picker to work but not the Dir function.
Alex Hedley  @Reply  
           
4 years ago
Any errors?
Scott Axton  @Reply  
        
4 years ago
Doug -
Did you also download the sample db?  Does it work from there?
It works fine for me (The After L2 db ).  

So...  If it does, either you missed a step or typed something wrong.
Use the sample to compare what is there and what you have in your db.  Sometimes you get great learning of things by tearing apart an example.
Kevin Yip  @Reply  
     
4 years ago
Hi Doug, this should populate the list box with all the file names in a folder.  Only file names, not subfolders, are included.  

Private Sub PopulateListbox()
    Dim fn As String

    ' Get the first file name in the folder.  Note that wild card is used.  You can use wild cards to retrieve select files.
    fn = Dir("C:\My Folder\*.*")

    ' If found, run do loop.  Note: Dir() returns an empty string if no file is found.
    Do While Len(fn) > 0

        ' Add file name to list box.
        Me!MyListbox.AddItem fn

        ' Get next file name in folder.  Note: Dir() with no argument is used for this purpose.
        fn = Dir()

    Loop

    ' Number of file names in list box.
    MsgBox Me!MyListbox.ListCount
End Sub
Doug Henderson OP  @Reply  
    
4 years ago
Kevin, that worked. Thank you very much.
Kevin Yip  @Reply  
     
4 years ago
You're welcome.  Forgot to mention that the listbox RowSource must be set to "Value List".  You must know that already.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 7:31:17 AM. PLT: 1s