Multiple images in a form.

  • Thread starter Thread starter Ken...
  • Start date Start date
K

Ken...

Guest
Could anyone help please.

I am a total novice with MS Access (2002) and coding so I am trying to learn by adapting the Northwind sample.

So far, one thing has completely stumped me and that is controlling images. I understand the benefits/pitfalls of storing images in the database and have concluded that it will suit me better to link my images via a text field.

What I am trying to do is add multiple images to the Northwind Employee Form. I have followed the help file and I can get additional images to display on the form, but I can not get the additional images to change for each record. The MS Access help only covers having a single image per record. I've concluded (right or wrong) that the Event Procedure is where I need to be experimenting, but I've had no luck so far.

Can anyone tell me if I can modify the Event Procedure in the Northwinds Employee sample to cope with multiple images, or is there another way?

Excuse me if any of my terminology is wrong... I really am new to this.

Thanks for any advice.
 
Is it is your intention to have a diferent image for each record on a form (eg. an employee database with each employee's picture in the record and on the form)?
If so, you must add a new field to your table. It must be an OLE Object type.
When entering the info on the form, right click the image area and select "Insert Image". The wizard will take it from there.
Hope this helps.
 
statsman said:
Is it is your intention to have a diferent image for each record on a form (eg. an employee database with each employee's picture in the record and on the form)?
If so, you must add a new field to your table. It must be an OLE Object type.
When entering the info on the form, right click the image area and select "Insert Image". The wizard will take it from there.
Hope this helps.

Hello Statsman, thanks for your reply.

Partly... I actually want multiple images (different) displayed fo each record on the form. To use Northwinds as an example... a portrait pic, a profile pic. etc.

Looking at the Northwinds example and the MS Access help file, it seems to suggest that I can achieve this without OLE !?. I'm not sure, but from what I can see Northwinds doesn't use OLE in the Employes form, but I am a real novice and glad to be corrected.

I can use the wizard to get additional images on the form, but I can't "control" them... ie changing for each record etc.
 
The recommended way to deal with images and Access is to store the images separately then store the path to those images in a text field. To display the image you use an UNBOUND Image Control and set the Picture property of the control to the path of the image file.

There would be two ways I would deal with multiple images per record.

1) Add a tblImages table like this:

tblImages
ImageID (PK Autonumber)
ImagePath
ImageType
EmployeeID (Foreign Key)

2) Have a separate field for each image type in your record (I would use this only if there were no more than 3 image types and each record would always have each type of image).

My preference would be to use option 1.

Once you have the images paths stored, you need to display the images on your form. There are 2 ways to deal with that.

1) Have a separate image control for each image type and set the picture property for each at the same time (in the On Current event). Example:

Me!imgPortrait.Picture = Me!txtPortraitPath
Me!imgProfile.Picture = Me!txtProfilePath

I would use this method only if I was using method 2 for stroring the path.

2) Have a single image control, but use an Option group or cycling buttons to change the currently displayed image.

For example:
Code:
Dim strImagePath As String

strImagePath = DLookup("[ImagePath]","tblImages","[EmployeeID] = " & Me!txtEmployeeID & " AND [ImageType] = " & Me!optImageType)

Me!imgPic.Picture = strImagePath
That code would go in the after Update event of the Option group. I'm also assuming that the ImageType is a number code from a look table that corresponds to the number in the option group.
 
Hello Scott,

Thanks for the reply.

I have been studying your comments really hard and I know it is my own inexperience and can see that you have done a great description, but I'm lost. In all honesty, this is why I am trying to learn by adapting the Northwinds example.

I've got as far as storing the image path to a text field (as per N'winds), but following the Access help file may have confused me. It say's "... an unbound picture or object, doesn't change from record to record. A bound picture or object can be different as you move from record to record".

The help file then goes on to explain how to add the image on the form, but then goes on to say click on the normal image tool to insert the pic., not the bound or unbound tool!. So I have follwed the instructions and have not found any bound/unbound controls/options. Obviously I'm real confused.

I feel there is a clue to where I am going wrong in your message. With the N'winds example, I seem to get everything I want until I come to editing the On Current - Event Proceedure to accomodate the additional images.

The obvious thing that hits me is, when I add the image to the form and then go onto edit the event procedure (Private Sub Form_Current), I am presented with the code for the existing image. Can I modify this to deal with multiple images or do I (somehow) create another E.P./code.

Sorry everyone, I realise this is tiresome for experienced people but I am really appreciating the help.
 
What you quoted is correct. An unbound object doesn't change from record to record. That's why you need to use the On Current event to manually make the change. If you use a bound Image control, then the image has to be stored in the database and we don't want that.

The On Current event kicks off whenever the current record changes. By setting the Picture property of the unbound image control in the On Current event you are effectively changing what the unbound image control will display when you change records.

You can deal with multiple images within the ONE On Current event (there is only one On Current event per form). However, that uses the method I don't recommend since it leads to denormalizing your database and cluttering up your form. I would prefer the option of selecting which image is displayed. But its your database and up to you what you do with it.

The real key to understanding this is understanding that the On Current event runs whenever you change records. Once you realize that, you see that it can be used to change the Picture property of any unbound image controls.
 
Scott, thanks again for your advice.

You have hit upon something that has, as you mention, increased my understanding. The "selection" of displayed images has, from your help, just dawned on me so has the basic operation of the EP.

I can't say that I understand it all, but you have given me something to go away and experiment with... and I will.

Thanks very much for your help and patience.

Ken.
 

Users who are viewing this thread

Back
Top Bottom