Open a Folder Beside an Access Database with a Form Button
Question details
The user needs an Access form button that opens a Pics folder in the same directory as the current database.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A user with limited VBA experience wants a button that works without hard-coding the database folder path.
- Observed behavior
- Clicking the button should open the adjacent Pics folder in Windows Explorer, or display a message if the folder is missing.
Confirm that a folder named Pics exists beside the Access database file containing the form. This Windows solution requires Access to allow VBA code to run; enable content only if you trust the database.
Call a public VBA function from the Access form button
Use the current database's folder to find Pics without hard-coding a drive or path.
CurrentProject.Path returns the folder containing the current Access database. In a split database, this is typically the front-end database folder, not the back-end data folder.
In Access, press Alt+F11 to open the VBA editor. Choose Insert > Module; do not paste the function into the form button's code window.
Paste this code into the new module: Public Function OpenPath() As Boolean Dim folderPath As String folderPath = CurrentProject.Path & "\Pics" If Len(Dir(folderPath, vbDirectory)) = 0 Then MsgBox "The Pics folder was not found: " & folderPath, vbExclamation Exit Function End If If (GetAttr(folderPath) And vbDirectory) = 0 Then MsgBox "Pics is not a folder: " & folderPath, vbExclamation Exit Function End If Shell "explorer.exe """ & folderPath & """", vbNormalFocus OpenPath = True End Function
In the VBA editor, choose Debug > Compile and fix any reported errors. Save the module with a name such as modFolderUtilities.
Open the form in Design View, select the button, and open its Property Sheet. On the Event tab, enter =OpenPath() in the On Click property.
Save the form, switch to Form View, and click the button. Windows Explorer should open Pics; if the folder is missing, Access displays its expected path.

Work with Office documents in WPS Office
WPS Office is a free, lightweight alternative for everyday documents, spreadsheets, and presentations. Its familiar interface and Microsoft Office format support make moving existing files easy. It does not run Access databases or fix Access form-button VBA.

Frequently Asked Questions
What should I enter in the button's On Click property?
In the button's Property Sheet, open the Event tab and enter =OpenPath() in On Click. The public function must be in a standard module.
Where should the Pics folder be stored?
Place Pics in the same directory as the current Access database file. CurrentProject.Path supplies that directory, and the function adds \Pics to it.
Why does Access say the folder cannot be found?
Check that the folder is named Pics and is beside the current database file. In a split database, check beside the front-end file containing the form, rather than assuming the path points to the back end.
Why doesn't the button run the function?
Confirm that OpenPath is a Public Function in a standard module and that On Click contains =OpenPath(). Also check the Access security warning and enable content only if you trust the database.




