How To Attach Files In An Access Database

If you noticed Access now has a datatype to add attachments. If you don’t want to program this with VBA as I show you how to do below, you can use it (if you dare :)).

I think Microsoft wanted to make things easier for the user, so they added the ability to add attachments as a field datatype.

Ok…if that’s what you want to do, but I would not recommend it. You really should store the file in the operating system and the file’s path in a text datatype field. In the case of Access, the datatype is “Short Text”. The database’s strength is to store data, and the operating system’s strength is to store files.

We don’t want to “bloat” the database with files, that’s what the OS is for.

The following example will simply show you how to attach files to a customer and then open the file paths you attached.

Attach File (s)

When you click the “Attach Files” button, you’ll get this code:

With the above code, you are able to select a file from your file system to assign to a customer.

Doing it this way you are selecting a file already in your file system.

So we choose the file, and the file’s path gets entered into the table.

To open the file and read it gets attached to the “Click” event of the “FilePath” textbox. This is the code:

This little bit of code actually calls a shell function (an api call) to “ShellExecute”, which is part of the windows operating system:

Make sure these shell api functions are in a module by themselves

The database is attached for you to check out. Let me know if you need help.

Download Attachments.accdb

Free! Subscribe To Our YouTube Channel!

facebooktwittergoogle_plusredditpinterestlinkedinmailby feather
Tags: , , , , , ,


Call Erik Now