Cause an image to change depending upon what you select in a combo box

Scythed

Registered User.
Local time
Today, 02:26
Joined
Aug 30, 2008
Messages
28
Does anyone know if there is a way to make a placeholder for an image so whenever you select an item in a combo box it changes to an image of that item stored in a folder?
 
In you Combo boxes on change event put some code like this;

Code:
If Me.ComboName.Value = "Condition1" Then
    
    Me.ImageName.Picture = "C:\Image1Location.jpg"
    Else
    
    Me.ImageName.Picture = "C:\Image2Location.jpg"
    End If

Of course you can test for as many conditions as you choose to display any number of images.
 
Thank You very much it worked
 
Just a teeny comment - the Change event may or may not be your ideal choice here. This will see the Picture property attempt to be set upon each update of the text in the combo (so were the user typing a value rather than selecting the picture property would be re-assigned with each keystroke). And it would be the previously selected entry that would be being re-assigned until the Value was updated.
OnClick or AfterUpdate would be more common ones - the value being updated by then and raised only when the value does change.

Alternatively (and possibly in conjunction) you could wrap any assignment of properties like Picture with a check that it isn't already so assigned. e.g.
Code:
If Me.ImageName.Picture <> "C:\Image1Location.jpg" Then
    Me.ImageName.Picture = "C:\Image1Location.jpg"
    'etc...

This is a small issue - the assignment of an image (unless it's of substantial size and over the network) is unlikely to be felt to a great degree. :-)

Cheers.
 
is there any way i can put a variable in the path name... i.e.

me.imagename.picture = "c:\path\"variable".jpg"

the varaiable will be from the combobox, so that i don't have to make a column to store the image path.
 
Thank-you very much, this is exactly what i was looking for!!!
 
Leigh is right on the money. Using OnChange is way too processor intensive, for the cited reasons. This type code really should go in another event, preferably AfterUpdate
 

Users who are viewing this thread

Back
Top Bottom