Passa al contingut principal

How to manage attached files with access. Options.

Hi all
This week's post is about how to manage attached files with MS-Access and VBA.

Introduction

Sometimes is useful and/or necessary to store attached files in our applications.
Let's see some examples:

  • A used car seller may have a database with all the vehicles on sale, and may need to have photos of the cars, to show them to the potential customers before seeing the cars. And also may want to store digitalized the papers of the car.
  • A real state business, has a file with each property, and may want to show the photos to the potential customers before visit, to restrict the number of properties to visit. And not only the photos, but also legal papers about the property.
  • A doctor, may want to save information about their patients, but sometimes this information is not suitable to be stored in a record, for example a bone scan or the results of some tests, but is useful to attach to the patient file to find it more easily.
  • A farmer may need to store data about the traceability of their products, and their suppliers send pdf documents with the information of the products. He must, also, send information to his customers when selling animals.
There are a lot of examples, I'm sure you have been thinking a lot of them while reading the post, and you have found sometimes with similar problems.

Solutions

There are some solutions to store this information using databases in general, and MS Access more specifically. 
MS-Access by itself allows to store the data using a special kind of field for this purpose. I've used it in the past, some years ago, but the results were not the expected, because the file grows exponentially, and it becomes difficult to manage it, it becomes slower and a big amount of space to do the backups is needed.
I'll try to explain how to store data without storing them directly to the data files.

Attached files with VBA

In this point it may be useful to take a look at a previous post, published last feb 10, about how to use an Options dialog box with Access. It may help, and I will use it later in other posts to enlarge today's post.
What is the main idea? The idea is to store the files in specific folders "controlled" by the program.
To control those folders we will use the Options dialog box, with one parameter, may be called, for example, FilesFolder, and will be the name of a folder on the HDD.

We have a table and in this case, each record has an attached file, only one and always one (or zero).
If we have been stored the name of the folder where the files are, we need simply to add a text field to the table, where we will save the name of the file. 
To have access to this file, we will use the GetParam public function to obtain the folder name, and we will concatenate it with a anti-slash and the name stored in the data table.
If you want to use the contents of the file in a form, you may use the FollowHyperlink statement to open this file with the by default program to open it.

What are the real advantages of this system?. Of course, the amount of space needed by the application.
Storing the files in the data table makes this datafile grows exponentially, and like this, we only store a string.

Final note

This has been a very short post to explain one option about how to store this information.
In nexts posts I will develop and release some files with examples.

I hope you like it. I'm working in a post about how to use the explained above to show those files in a carousel of images. I will try to post it this week.

Have fun!

Comentaris

Entrades populars d'aquest blog

How to export data from access to a text file

Introduction Hi all Today's post is about a set of functions to export data from Access to text files. I wrote the next functions years ago, when working on a big project and I had to export some of my data to another system, by text files, regularly. I needed something easy for the users, and transparent. I will explain what I did, and how. At the end of this post you will find a link to download the example of code. Feel free to modify it. Sometimes it happens that we need to export data. Of course, almost always we may write to another database. As I said before, I wrote this code to cover a need. This is a brief: I've been working for a company who mades canned fish. They had their ERP software, made by a external firm, and mantained across more than 20 years. When I entered, I had to write a software to control the production process and traceability. Of course, my processes (my software) was a subset of all the other software, and they had to communicate th

Use of listboxes as a data summary instead data forms

Hi all This post is an extension of the previous post ( how to develop a carousel ). Here I will show how to manage a summary form linked to a detail one, in order to show data and detail them. I want to clarify that this is not "the way" to work with access, this is "a way". This is the way I use. After been developing Access applications, I've found this is a good solution, and I use it almost always. I will improve the previous example, the used cars seller adding a new form. The new form has a listbox and some buttons (add, delete, duplicate and modify) to perform those operations. All those operations are solved using VBA, as you may see. The new form is named Main. You may see in the next screenshot I've added new records. Once the form is loaded, the data are stored in the listbox using the Form_load event. The objects are named as follows: Button Add is named cmdAdd Button Duplicate is named cmdDuplicate Button Delete is named cmdD