Image in form dependant on record

expublish

Registered User.
Local time
Today, 20:54
Joined
Feb 22, 2002
Messages
121
I have a table called Units. In it there are various fields related to the unit. One field is called 'Path to image'. This contains the network path to the image that relates to that record.

I have a form based on the table. I have all the fields displayed, apart from 'Path to image'. I would like to be able to have the image that the path leads to displayed for each record. So, as you browse between records, the image changes to the relevant image.

I was going to insert an image and change the data source, but it won't let me.

How do you do this, as I am sure it can easily be done?

TIA

Scott.
 
Hi
smile.gif


The way I do this image change is as follows

1. Put all images in any fixed directory
2. Refer the path of the image in my code.
3. Place an unbound Image control in ur name and name it as Pic
4. On current event of your form write:

Private Sub Form_Current()

Dim strpath As String
Dim strpath1 As String
Dim strext As String
Dim strfile As String

If Picid > 0 Then
'setting path of the picture files
strpath1 = "C:\My Documents\My Files\Pics\"
strfile = Picid
strext = ".gif"
strpath = strpath1 & strfile & strext

'MsgBox strpath

pic.Picture = strpath

End If

Note that the field name is PicId. So your field name should match with the name of the picture file stored in your hard drive.

Hope it helps

Cheers!
Aqif
 
Thanks for your help.

I have actually worked it out myself this morning.

What I did was change the 'Path to image' field from text to an OLE object. For each record I right clicked the field in datasheet view and clicked select object. I then browsed to the relevant image and selected it.

I then inserted a bound onject box into my form and made the control source the 'path to image' field. It does the trick.

Another tip, make an image that shows 'No Image Available' for records that do not have an image and select this in the first stage above. This prevents an empty box being shown on the form. I also locked the object box so changes cannot be made to the image.

Goes to show that tinkering does help sometimes!

Scott.
 

Users who are viewing this thread

Back
Top Bottom