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:
Now, that sounds easy enough right! noooo. There are a few more changes I wanted to make:
To do this was tricky - you have to
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.lblOps.Caption = "THIS IS THE CONTENTS OF THE FOLDER:"
Me.WB1.ControlSource = "=""\\YOURSERVER\YOURSHARE\SAMPLEDIR"""
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
Me.lblOps.Caption = "THIS IS THE CONTENTS OF THE FOLDER:"
Me.WB1.ControlSource = "=""\\YOURSERVER\YOURSHARE\SAMPLEDIR"""
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
Copyright © 2024 - All Rights Reserved