How to display an image based on the list-box selection in a form.

G

Guest

I am trying to figure out how to display an image on a form based on a
list-box selection. I am only working with about 8 different images. I
want to display an image of a cpu when "cpu" is selected, an image of a
printer when "printer" is selected, etc. I created a table and embedded
the images and I have created the form. I have tried inserting the image
field but have not been able to make it conditional based on the selection in
the [Equipment Type] field. Is there a way to do this without a whole lot
of VB programming. Please advise....
 
A

Arvin Meyer [MVP]

In single form view, you can put the path to an image in a table and add it
to a column in your listbox. The column width can be set to zero (0) so that
you don't display the path. So let's just say the listbox record for CPU
looks like:

Column 1 Column 2 Column3
ItemID Description Path

1 CPU C:\Pictures\cpu.jpg

Your code might look something like:

Sub MyListBox_AfterUpdate()
Me.imgControl1.Picture = Me.MyListBox.Column(2)
End Sub

Column(2) being the third column in a zero based column index.
 
G

Guest

How do I make it conditional - if the user selects cpu - have a picture of a
cpu appear on the form??

Thanks!

Arvin Meyer said:
In single form view, you can put the path to an image in a table and add it
to a column in your listbox. The column width can be set to zero (0) so that
you don't display the path. So let's just say the listbox record for CPU
looks like:

Column 1 Column 2 Column3
ItemID Description Path

1 CPU C:\Pictures\cpu.jpg

Your code might look something like:

Sub MyListBox_AfterUpdate()
Me.imgControl1.Picture = Me.MyListBox.Column(2)
End Sub

Column(2) being the third column in a zero based column index.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

dceglar1 said:
I am trying to figure out how to display an image on a form based on a
list-box selection. I am only working with about 8 different images.
I
want to display an image of a cpu when "cpu" is selected, an image of a
printer when "printer" is selected, etc. I created a table and embedded
the images and I have created the form. I have tried inserting the image
field but have not been able to make it conditional based on the selection
in
the [Equipment Type] field. Is there a way to do this without a whole
lot
of VB programming. Please advise....
 
A

Arvin Meyer [MVP]

Exactly. I also have some additional code in a demo app that might give you
some ideas:

http://www.datastrat.com/Download/Picture2K.zip
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

dceglar1 said:
How do I make it conditional - if the user selects cpu - have a picture of
a
cpu appear on the form??

Thanks!

Arvin Meyer said:
In single form view, you can put the path to an image in a table and add
it
to a column in your listbox. The column width can be set to zero (0) so
that
you don't display the path. So let's just say the listbox record for CPU
looks like:

Column 1 Column 2 Column3
ItemID Description Path

1 CPU C:\Pictures\cpu.jpg

Your code might look something like:

Sub MyListBox_AfterUpdate()
Me.imgControl1.Picture = Me.MyListBox.Column(2)
End Sub

Column(2) being the third column in a zero based column index.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

dceglar1 said:
I am trying to figure out how to display an image on a form based on a
list-box selection. I am only working with about 8 different images.
I
want to display an image of a cpu when "cpu" is selected, an image of a
printer when "printer" is selected, etc. I created a table and
embedded
the images and I have created the form. I have tried inserting the
image
field but have not been able to make it conditional based on the
selection
in
the [Equipment Type] field. Is there a way to do this without a
whole
lot
of VB programming. Please advise....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top