Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display an image on a form 2

Status
Not open for further replies.

robojeff

Technical User
Dec 5, 2008
220
US
I would like to incorporate an image of a part on a form so that when I select a part number in a combo box that the picture of the item appears.

Can some one direct me to an online instruction of how to set this up?

Thanks
 
Hi Robojeff,

In pre-2007 versions (and maybe in 2007) there was an image control on the standard controls menu for which you could set the picture property to the image's path either programmatically or in the properties dialog.

And rummaging thru mental archives, there used to be a Kodak ActiveX control (A2K and earlier) which did much the same thing. I think Microsoft replaced this with another ActiveX control along similar lines.

Cheers, Bill
 
thanks Formertexan-

After a little digging, I also found that I could use a button on the form and change the picture associated with it from a bitmap image.

I am guessing that the picture that is displayed on the button can be set from the code based upon an OnUpdate Event of the part number selected in the combo box but I am unsure if this means that the bitmaps used must always be set in a standard place on what ever PC happens to be running the database or if there is a way to tie these together so that the database is stand alone and portable by itself...

Does anyone have any strategies on how to do this?
 
Hi Robojeff,

You pass the control a relative path. This means using a path that is relative to the folder your application is in("..\\ApplicationFolder\Photo.bmp") rather than an absolute path (C:\\Applications\AllUsers\ApplicationFolder\image.bmp"

Using a button may work for you, but it won't provide much flexibility. Acceptable image file types and display properties may be some of the issues you'll encounter.

Cheers,
Bill
 
Thanks for the ideas... I have progressed to the following but still need some help...

I have a combo box with the following row source:

SELECT CountryDef_tbl.Country, CountryDef_tbl.PN1 FROM CountryDef_tbl ORDER BY [Country];

The Country Field is the country where the part is used and the PN1 field is the part number of the part.

As I mentioned earlier, When I select an item in the Combo Box, I would also like to display an image on the form showing what
that part looks like in an image bitmap that I have placed on the form. In order to do this, I am guessing that
I can just change the hyperlink to it.

I have a table with the part number and a hyperlink to the bitmap in my table part_tbl as part_tbl.partnum and
part_tbl.pic

I am having a tough time attempting to grab the selected combo box value for PN1 (the part number). My intention is
to do a Dlookup on this number in my part_tbl to get the hyperlink to change the bitmap but I am only able to
get ther first variable field (country) from the combobox with:

part= Me.Combo1

Is there a better way to do this and still keep the row source as I have it set up now? (I want to display all the info in the combo box for the user)

Once I have the hyperlink stored in a variable such as HL then I am assuming all I need to do is a simple command such as Me.Image4.Picture= HL


thanks
 
Hi Robojeff,

1. I suggest you amend the listbox's rowsource to include any hyperlink information rather than go through another step of using DLookup.

2. Have a look at the Column property of listboxes.

Cheers, Bill
 
Thanks formerTexan-

I added a hyperlink type field to my table and populated it with the hyperlink to each of the corrsponding bit maps but when I added it to my rowsource, the combo box simply displays the path in my combo box.

I then added the following to my OnUpdate event for the combo box, but this isn't correct either as I get an object required error with the following:

Me.Image4.Picture = PowerCord_tbl.pic

Not sure how to make that image pop up on the form...
 


I got it to pull the bitmap onto the form with the following code:
Code:
Dim X As Variant, Y As Variant
 Y = Me.Combo1
 
 Y = DLookup("[pic]", "CountryDef_tbl", "[Country] = 'Bolivia'")

 Me.OLE1 = Y

But I get a Run-Time Error '2001'" You cancelled the previous operation...if I change the line to get the combo box value selected to:
Code:
 Y = DLookup("[pic]", "CountryDef_tbl", "[Country] = X")

What am I doing wrong and how can I get it to pull the bitmap from my table?

 
Thanks Aceman but "How to Display Images in a Form or in a Report Without Storing the Images in a Table"
gives me a broken link for some reason and I can not read it...

any other links where I can learn this ?

Thanks
 
robojeff . . .

Try here Article 148463

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks Aceman-

There is something going on with my PC here at home and I can't access any Microsoft web sites for some reason...

I think I know where you are going with linking the bitmaps vs. embedding them as the later does grow the database but
on the other hand, I would like for this to be self-contained and if these images are not embedded, doesn't
that also mean that I would have to have the bitmaps copied to a specific location along with the database if I choose
to have this on more than one PC?

If this is the case, then I need to resolve this Dlookup issue unless there is another way...

Any ideas what is causing the Run-Time Error '2001'" You cancelled the previous operation "
I get this error with both of the following so I am guessing that my syntax is wrong...

X = Me.Combo1
Y = DLookup("[pic]", "CountryDef_tbl", "[Country] = X")

or

X = Me.Combo1
Y = DLookup("[pic]", "CountryDef_tbl", "[Country] =" & X & "")
 
robojeff . . .

You do realize [blue]a hyperlink will open the default application associated with the files file type![/blue] [surprise] Also ... a hyperlink is a [blue]multivalue field[/blue] and can not be used as criteria. You'd have to use the [blue]HyperlinkPart[/blue] method to extract the path & filename. Try performing [blue]Debug.Print Me!pic[/blue] and see what you get!

At the very least you need to change the hyperlink field to text.

As for your code try:
Code:
[blue]   X = Me.Combo1.Column(1)
   Y = DLookup("[pic]", "Part_tbl", "[partnum] = '" & X & "'")
or
   Y = DLookup("[pic]", "Part_tbl", "[partnum] = " & X)[/blue]

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks Aceman...

I will look at the two links that you sent me when I get back into the office tomorrow to learn more about How to Display Images in a Form or in a Report Without Storing the Images in a Table
 
Robojeff,

Using non-embedded images doesn't mean you have to use fully qualified paths. You can use relative paths. Relative paths would indicate where the images are relative to the Access application. It could be the same directory or a subdirectory or a directory up. Access is clever enough to know that if your application is in:

C:\Documents and Settings\All Users\YourApplication.mdb

then the following relative path

.\yourImage.JPG

is equivalent to:

C:\Documents and Settings\All Users\yourImage.JPG

This frees you up from worrying about where the application and photos are placed on someone else's computer or drive. And this is generally how applications and webpages are set up.

However if you want to go with embedded images and store them directly in tables, perhaps the easiest way is to use the Bound Object Frame control and set its control source to the field in which the images are stored (assuming the field is included in the form's recordsource).

Remember that database bloat does occur with the storage of non-icon type images, so you will have to weigh the conveniance factor against the number, size and type of images that may be stored.

Cheers, Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top