How to obtain a path and name from a bound object

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

I have been struggling with this for a while now.

I have a form which has a bound object frame on it. When the form is in form
view and I right click on the bound frame, I can insert an image via 'Insert
Object', 'Create from file' and browse to the picture file I want embedded
in a table field called 'Picture Preview'.

What I want to do is write some VBA code that will operate on (maybe) the
'On Update' event so that it will determine the path and filename that has
just been embedded and to place that string into a hyperlink field (called
Image) in the same table.

My question is - how to I get hold of the path and filename of the picture
object I am inserting.

Thanks in advance for any help you can provide.

Martin
 
Hi,

Even if adding pictures to database is technically possible, it isn't a
reccommened approach, because this will make your MDB increase very much in
size.
A better approach will be to use a field with text datatype, and to store
the pathname to your picture.
You bind the form to the table who contains the Imagefilename field (or to a
query who contains that field)
Then, on your form, add a image control. You have to select an image in
Design mode, since Access doesn't allow you to add a image ctrl on the form
without any image set in Picture property. This image won't be used in the
application actually, it is only used to "trick" Access to let you add the
image ctrl on the form.
Also, you should set the PictureType to Linked (to avoid embeding the image
in the MDB)

Then, in Form_Load add the following line (to clean up the image)

me.imgPreview.Picture = ""

In form_current event you update the image control with the actual image you
want, as below:

' suppose you have a bound form, the image filename is stored in ImgFileName
field, and your image preview control is called imgPreview
......
me.imgPreview.Picture = me!ImgFileName

To make your application location independent (that is, to be able to run it
from any location), you can store all images in a subfolder of the
application folder (suppose in Images folder). Then in the ImgFileName you
can store only the filename (without the path), and in form_Current methoid
calculate the real path name based on file anme and current application
folder.

If you have any further questions or need more asistance, you can contact
me.

HTH,
Bogdan

_________________________________
Independent consultant
 
Back
Top