Browse to File Function in MS Access

If you are using images frequently and saving them as attachments in MS Access database, you might end up with a heavy file. The software has also a limit of 2GB file size. To avoid that situation, you may like to save your images in a separate folder and display them in the database by a text path. Through the following example, I will show you how to do it.


The example has a table and a form with the fields: ID (auto number) and Path (text). There are two more elements on the form: BrowseTo button and Image frame. When a user clicks on BrowseTo button, it will browse to a file and save its path in the field Path. If the file is an image, it will be displayed in the frame Image.

After creating all the required elements, right-click on BrowseTo button, go to Properties > Event > On Click, select [Event Procedure] and click on ellipses (three dots) to open VB application. Select the code area and paste the following code:

Private Sub cmdBrowseTo_Click()
Dim fdg As FileDialog, vrtSelectedItem As Variant
Dim strSelectedFile As String
Set fdg = Application.FileDialog(msoFileDialogFilePicker)
With fdg
.AllowMultiSelect = False
.InitialView = msoFileDialogViewDetails
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
strSelectedFile = vrtSelectedItem
Next vrtSelectedItem
Me![Path] = strSelectedFile
End If
End With
Set fdg = Nothing
End Sub

Stay in the VB application, go to the menu Tools > References and check Microsoft Office xx.x Object Library.

Before testing the button, right-click on the frame Image, go to Properties > Data > Control Source and select Path, so that it can display the image through the path.


3 thoughts on “Browse to File Function in MS Access

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s