Image change based on combo box selection (1 Viewer)

Bosve

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2010
Messages
35
Hi

I have very simple database consisting of one table "tblMain" and one form
"frmMain". On the form i have a two cascading combo boxes and two text box
which get their data from combo boxes.

The issue that I have is I am trying to add image to my form which is based
on selection in a combo box so that ArticleNR->shows image1 and so on. As a
novice to Access I have searched the forum but there are so many diffrent
solutions that I don't know where to begin.
 

John Big Booty

AWF VIP
Local time
Tomorrow, 07:37
Joined
Aug 29, 2005
Messages
8,263
Check out the attached should give you some pointers
 

Attachments

  • Combo Change Image.mdb
    192 KB · Views: 482

rohnds

Registered User.
Local time
Today, 14:37
Joined
Jul 20, 2010
Messages
19
You can change the .Picture properties of the image to the file using vba.

Create an event BeforeUpdate for the combo and then in that procedure assigned the file name the .Picture property of the image.

Private Sub Combo5_BeforeUpdate(Cancel As Integer)
me!combo5.Picture="File name"
End Sub
 

Bosve

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2010
Messages
35
You can change the .Picture properties of the image to the file using vba.

Create an event BeforeUpdate for the combo and then in that procedure assigned the file name the .Picture property of the image.

Private Sub Combo5_BeforeUpdate(Cancel As Integer)
me!combo5.Picture="File name"
End Sub

Sorry I don't understand how will this update the image box. Shouldn't that be an after update event?
 

Bosve

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2010
Messages
35
Check out the attached should give you some pointers
Well I do understand your example but it is too simple for my purpose. I have a table with 100 records and to set a true or false statment on every image would be very time consuming.
 

John Big Booty

AWF VIP
Local time
Tomorrow, 07:37
Joined
Aug 29, 2005
Messages
8,263
Here's a slightly more sophisticated example. This one should scale nicely to meet your requirements.

You will get an error on start up but click OK and the DB will work perfectly from there.

Make sure you copy the DB and the file Flags to the same location.
 

Attachments

  • Flags.zip
    76.9 KB · Views: 810

Bosve

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2010
Messages
35
Here's a slightly more sophisticated example. This one should scale nicely to meet your requirements.

You will get an error on start up but click OK and the DB will work perfectly from there.

Make sure you copy the DB and the file Flags to the same location.
Now that was more like what I was looking for except i have trouble to get it work in my db. I understand the principle but when I try to apply that to my db it doesn't work.

The combobox solution is same as I have except i have cascading combo boxes so that combobox2 is controlled by selection in combobox1.
In the "flags" query there is this line of code:
Application.CurrentProject.path & "\Flags\" & [flagloc] AS Expr1
I understand it is supose to point the image location but i doesn't work for me and this is how the query looks like in my form:

SELECT tblMain.ArticleNR, tblMain.Name, tblMain.Weight, tblMain.FlagsLoc, Application.CurrentProject.path & "\EP\" & [flagloc] AS Expr1
FROM tblMain
WHERE (((tblMain.Chemical)=[forms]![frmMain].[cmbChemical]))
GROUP BY tblMain.ArticleNR, tblMain.Name, tblMain.Weight, tblMain.FlagsLoc
ORDER BY tblMain.ArticleNR;
 

Bosve

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2010
Messages
35
Here it is...
 
Last edited:

John Big Booty

AWF VIP
Local time
Tomorrow, 07:37
Joined
Aug 29, 2005
Messages
8,263
Firstly you need to think about normalising your DB.

Then you need to read up on cascading combo boxes or here. From the sample you have provided the combo boxes neither cascade or even need to cascade.

Once you have those two concepts working on your DB, then we can start talking about changing images as the combo boxes change
 

Bosve

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2010
Messages
35
Firstly you need to think about normalising your DB.

Then you need to read up on cascading combo boxes or here. From the sample you have provided the combo boxes neither cascade or even need to cascade.

Once you have those two concepts working on your DB, then we can start talking about changing images as the combo boxes change

Well i took a look on the info you provided and I got the comboboxes working now. I have read the article about normalization but as novice to access it didn't help me that much so that could be something for another thread. Even though I copied much of the code from the flagsDB it still doesn't work in my db. I get the error mesage "invalid use of null" and later on another error message that my images can't be opened.
 

Attachments

  • fruitsDB.zip
    144.4 KB · Views: 236

John Big Booty

AWF VIP
Local time
Tomorrow, 07:37
Joined
Aug 29, 2005
Messages
8,263
Good work getting the Cascading combo boxes working :)

I would however seriously suggest that you work on getting your head around the concept of Database Normalisation, as this is a corner stone to good DB design.

The reason that you were getting the Null error, was because the image address was in Column 5 of the second combo not column 3. Having addressed the issue of the column count you also need to ensure that your Combo actually has 6 columns so you can refer to column 5. The columns in a Combo Box are zero index, that is the first column is column 0 and the second column 1 and so on.

Your DB should now work as expected other than a reference to an image that does not exist.
 

Attachments

  • fruits-100804.zip
    155.9 KB · Views: 305
Last edited:

Bosve

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2010
Messages
35
Good work getting the Cascading combo boxes working :)

I would however seriously suggest that you work on getting your head around the concept of Database Normalisation, as this is a corner stone to good DB design.

The reason that you were getting the Null error, was because the image address was in Column 5 of the second combo not column 3. Having addressed the issue of the column count you also need to ensure that your Combo actually has 6 columns so you can refer to column 5. The columns in a Combo Box are zero index, that is the first column is column 0 and the second column 1 and so on.

Your DB should now work as expected other than a reference to an image that does not exist.
Thanks! The DB works now as expected. :)
 

Users who are viewing this thread

Top Bottom