DEMO OF THE USE OF csXImage WITH MS ACCESS

REQUIREMENTS

The trial version of csXImage (csXImageTrial.ocx) must be installed.  This is available as a free download from http://www.chestysoft.com/ximage/download.asp
MS Access must be installed.
One of the files AccessDemo.mdb or AccessDemo.accdb, is required because these contain the sample database.


DESCRIPTION

This example shows the use of csXImage for storing and retrieving images to/from an Access database.  Two different methods for using csXimage are shown.  These are the use of the control on an Access Form and on an Access Report.

USE IN A FORM

csXImage includes two methods, ReadBinary2 and WriteBinary, which can be used to store and retrieve images as a sequence of bytes.  This sequence will depend on the file format that is chosen, e.g., BMP, JPEG etc.  Any of the file formats supported by csXImage can be used.

In an Access database, the data type of a field can be set to "OLE Object". This data type can be used to store any kind of data, and when used with ReadBinary2 and WriteBinary, it will store images.

AccessDemo.mdb includes a form 'ImageForm'.  This form allows a user to step through the images contained in the database.

The form includes several command buttons, each of which runs VBA code.

The 'Load File' button displays a dialogue allowing the user to browse for an image file to open.  Any image file in a format supported by csXImage can be loaded onto the form.

After an image is loaded from file, the 'Store to DB' button stores the image into the current database record.  The WriteBinary method is used to do this.

Two command buttons are also provided to allow the brightness of the image to be adjusted up or down, before storing to the database.  This is an example of how the many functions available in csXImage can be incorporated into an Access application.

USE IN A REPORT

The Access demo provided has several images already loaded into the database.  Most of these images are simple geometric shapes (squares, circles) in various colours.  The 'Description' field contains an appropriate text string, e.g., "Green Square".

A query has been set up in the demo to search for images where the Description field includes a chosen text string. For example, this query can find all images which include "Red" in the description.

An Access report has then been configured to display those images. 

The csXImage control is again used to read the image data from the database field, using the ReadBinary2 method.  When used in an Access report, csXImage does not always display correctly, so the data is then transferred to a standard Access Image control, while the csXImage is kept in the background with its Visible property set to 'False'. The code needed to process the image in this way is contained in the 'Detail_Format' event procedure. 

TROUBLESHOOTING

If csXImageTrial.ocx is installed, there is no reason why this demo should not work with any version of MS Access.

If the demo is modified, or another application developed using csXImage and Access, there are a number of issues to be careful of, which could prevent the application from working:

1. Two versions of the database are provided, an older .mdb file and a newer .accdb file. One of these should work with your version of Access.

2. In a Report, csXImage will not display correctly, so the technique used in this example, to transfer the data first to a standard Image control, must be followed.

Chestysoft, July 2018.
Website: www.chestysoft.com