Rivercity Technology Services LTD Logo
About Us
Icon showing a support technician
IT Support Services
Cybersecurity Risk Management at one predictable flat rate.
Icon of light bulbs on a laptop screen
IT Consulting
Business optimization through the smart use of technology.
Icon showing a hand holding a phone
Business Phone Services
VoIP Telephone solutions from RCT. 
Icon showing a database and a cloud
Backups & Recovery
Cloud & On Premise - ready to recover!
Icon showing website wireframes
Website Development & Hosting
Web design and full hosting & maintenance packages!
Icon showing an envelope being opened
Modern Email Management
Microsoft 365 email provisioning, security & management.
Icon of a magnifying glass inspecting binary code on a computer screen
Cybersecurity Risk Assessment
Internal auditing to help identify potential cyber threats.
“You’re giving me the ‘it’s not you, it’s me’ routine? I invented ‘it’s not you, it’s me.’ Nobody tells me it’s them not me; if it’s anybody, it’s me.”
- George Costanza
Learning CenterNewsletterContact Us
Book A Consultation
Illustration of a person writing a blog post with a pencil

Listing Files From A Directory In An Access Form


How to create a box on a Microsoft Access form

A recent challenge i ran into was how to display files from a folder in an Access database form.  After a LOT of googling, I discovered there is not much out there on this topic, and what was there was overly complex and not what I wanted.  Hence my blog today.  The basic steps are this:

  1.  Create your form.
  2.  Insert a Web Control Object on the form.
  3.  Set the control source of the web control to the folder you are want to display.

Now, that sounds easy enough right!  noooo.  There are a few more changes I wanted to make:

  1.  Display the filenames in full list view, not icons horizontally across the screen
  2.  Make it so clicking a button would change the folder being displayed

To do this was tricky - you have to

  1. Create a button that sets the control source to the new path
  2. account for the = symbol and " symbols of the path being included
  3. turn on a timer for a few milliseconds so the webcontrol can load the data
  4. set the webcontrol to change the view to list (or other options) after the timer is expired, turn off the timer.

This is NOT well documented, in fact - I didn't find any references on line about using a timer for this to make it work, and had to do a lot of testing to make it do what I wanted.  And what's neat about this vs a listbox or other methods, is your browser properly shows the icons, allows sorting by clicking column headers, and generally behaves rather nicely!  I was impressed.  No special references needed, no complex module.

In this case, WB1 is my webcontrol box, and I used a button than gets a UNC to a server with a shared folder in this example.  You could easily replace it with something like "C:\Windows".  You can add more buttons, or make a dropdown that gives you a list of paths, etc...lots of options.  This example is just what will display the results for you.

YES, you need the goofy quotes in the beginning and end of the code,  and the "=".  Otherwise it will NOT work, you'll be missing required elements of the control source.

The options for currentviewmode are:

1 = Icons
2 = Small icons
3 = List
4 = Details
5 = Thumbnails
6 = Tile
7 = Thumbnail strip

I played around with adding an HourGlass timer, as sometimes the form loading content took more than a few seconds.  You don't need it though.

So here is the resulting form code (without all the fancy error handling and what have you):

' this is my button

Private Sub Command52_Click()
Me.WB1.Object.Document.currentviewmode = 3
Me.TimerInterval = 500
End Sub

'I do this so when the record is loaded it sets the view properly

Private Sub Form_Current()
DoCmd.Hourglass True
DoCmd.Hourglass False
Me.TimerInterval = 500
End Sub

'this is the timer code, which is actually VERY simple

Private Sub Form_Timer()
Me.WB1.Object.Document.currentviewmode = 3
Me.TimerInterval = 0
End Sub

Mitch Redekopp
Article Written by Mitch Redekopp

Get in Touch

Need IT Services or Cybersecurity for your business? Have tech questons? Contact us today, we'd love to help you!
Blog Sidebar Contact Form
Related Articles
Rivercity Technology Services LTD logo
We are your IT department. How would you like to manage your risk?
201-116 Research Dr,
Saskatoon, SK
S7N 3R3


Copyright © 2024 - All Rights Reserved