PDA

View Full Version : Solved: Attach Picture



mtnco80517
08-10-2011, 03:51 PM
Hello Everyone,

I have simple issue I need your help with. I have a form with a field that is a combo box based on a table in the database (ex: the field is 'Products'). I would like a picture of the item selected (the 'Product') to appear on the form after the user makes his/her selection. How do I do this.

Thank you for your assistance!

gkoliver
08-18-2011, 10:57 PM
There are likely a million ways to solve this problem, but this is how I would do it (Note: Air code!). Assumption: this is a static database, located on a company server or some such, and you have images available, and you can store those images somewhere everyone can get to. If you are moving this puppy around, you'll have to either embed the images, which causes significant bloat, or use relative addresses, which requires a little more programming.

Add another field to your Products table called "strImageAddress". Put the address of the image for each product in the field. This is actually the most painful part, but sort of necessary :yes . If you have them named in some consistent way, you may be able to programatically do this, but that's likely not worth it unless you have a zillion products.

Then in the form you want the image to appear in, do three things:

1) Add the image address column to the combobox (unless you're using the combobox to change records in records in a form, in which case you can just add the control to the form). You can make the column width zero, so it doesn't show. Pay attention to which column it is (the index), zero based: the first column (perhaps ProductID) is 0, the second column (perhaps Product) is 1, and the third column (perhaps strImageAddress) is 2, etc.
2) create an unbound image control. It will look like a blank square in design view, and not show in form view, if you do it right.
3) On the AfterUpdate event for your combobox, have this:

image1.Picture = me!cmboBoxProduct.Column(2) (if it was index 2) or image1.Picture = me!strImageAddress if you're moving around the product recordset.

Hope this helps!

gko