Others

Open a Folder Beside an Access Database with a Form Button

Muhammad TalhaMuhammad Talha Nov 25, 2026 868 views

Question details

The user needs an Access form button that opens a Pics folder in the same directory as the current database.

Open a Folder Beside an Access Database with a Form Button
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.
Before you start

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.

Solution 1Recommended

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.

1
Open a standard module

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.

2
Paste the function

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

3
Save and compile the code

In the VBA editor, choose Debug > Compile and fix any reported errors. Save the module with a name such as modFolderUtilities.

4
Set the button event

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.

5
Test the button

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.

Call a public VBA function from the Access form button
Keep the folder with the database: If you move the database, move the Pics folder beside it as well. Users must also have permission to access that folder.
Free Microsoft Office alternative

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.

Use a familiar interface to work with everyday Office filesOpen and edit Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXManage documents and spreadsheets alongside your database-related workUse a free, lightweight office suite for common tasks
microsoft office alternative - wps office

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.