Bound image control

  • Thread starter Thread starter jrfishe1
  • Start date Start date
J

jrfishe1

Guest
Hello,

I'm pretty new to Access, so forgive me if this question is more complex than it looks:
I have a combo box on my form where a user selects a bird species (such as "European Starling"), and I want to make a bound image control (or something like it) to display a picture of the bird they select. This is different from the example in Northwind b/c I want the picture to automatically reflect the choice the user makes. I don't want/need to store the image in my table, I just want the user to see the picture. I don't want the species field to be a hyperlink b/c I just want the species name in that column. Is there a way to create a second text field which gets a hyperlink based on species from a table, and then base an image on this second field? Or an easier solution? Do I need a 'refresh' button so that if they change the species the image refreshes or will that happen automatically with each selection? I don't know VB but I'm willing to experiment a bit is someone can steer me in the right general direction. Thanks!

-Jon
 
Make a blank table with 2 fields.

Field Name = Picture
Data Type = OLE Object

Field Name2 = BirdName
Data Type = Text

Save the table. Run the table in datasheet view

Right click on Picture first record. Select Insert Oject. Run through the directory drive and select your picture. Give it a bird name..

Make a form from your table. BirdName field use a combo box and paste the code below In After Update...

' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[BirdName] = '" & Me![ComboBoxName] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark


hth,

Michael
 
thanks!

Thanks a lot, I tried your code but I'm still having trouble. We have a table called Reports that takes data from the WildlifeReports form, and looks up the species from the BirdName field of the BirdSpecies table. The wildlife combo box is BirdSp So, we tried this in 'after update':

' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[BirdName] = '" & Me![BirdSp] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

but I get an error saying that it doesn't recognize 'BirdName' as a valid field or expression. I also tried changing it a bit to:
rs.FindFirst "BirdSpecies![BirdName] = '" & Me![BirdSp] & "'"
since I thought it might be looking for BirdName in the record table instead of the lookup table, but I got the same error.

Does anyone know what I'm doing wrong? I apologize for my ignorance, but I'm trying to learn...
 
Last edited:
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "BirdSpecies![BirdName] = '" & Me![BirdSp] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Get rid of BirdSpecies! second line after rs.FindFirst


hth,

Michael
 
Ukraine82 said:
Get rid of BirdSpecies! second line after rs.FindFirst

Sorry, I had a typo in the last post. I originally tried it without that; that line looked like this:
rs.FindFirst "[BirdName] = '" & Me![BirdSp] & "'"

and that was when I first got the error. I tried the BirdSpecies! to see if it would help. I've double checked that all the names are correct, there are no spaces in the names or anything like that. Any other suggestions? Many thanks,

Jon
 
Try this code in After_Update for a combobox.

Me.RecordsetClone.Findfirst "[FieldName] = " & Me![ComboBoxName]
Me.Bookmark = Me.RecordSetClone.Bookmark


If that doesn't work, than you might want to attach your database so I take a look at it.


Michael
 
Working with jrfishe1

I am working with jrfishe1 on the bound image. I have tried the new code yet recieved an error 3077 ...something about a comma; however, I check the code and it was as you had posted with the exception of the fieldname and comboboxname. I have posted the database online :
https://netfiles.uiuc.edu/jrrose1/www/wildlifepatrol.mdb

In the database you will find a form called WildlifeReports, it is in this report where the combo box in question is located. The combo box name is BirdSp. Currently the comb box looks up the values from table "BirdSpecies" and reports the value in table "Reports". We would like to have a picture of the bird appear to on the same form page when a bird species is selected.

We really appreciate your help!


Jamie
 
I have your database. I'm going to take a look at. I'll have the answer for you tomorrow cause I'm leaving work now.

Michael
 
I've looked at your database. The reason why you can't get the cascading combo box work is because you made your Wildlife form only from report table. That is why it won't recognize the BirdSpecies table. You can make a query from 2 tables and connect it to a form.

I wish I can help you more, but I'll be out of the office.

hth,

Michael
 
Hi,
I have tried the query path but yet to have any luck. I am beginning to try a new route by first inserting a bound object. For the control source I have referred to the field containing the bird names. ( I believe I have it referring to the appropriate table.) I feel I need to somehow set in the control source that the bird name calling the picture is the same as the bird name in the combo drop box. I have only started using Access this month, and have not learned all the options. Thanks for your repeated help.
Jamie
 
I would suggest that you not insert pictures into a table as this will increase the size of your database to an almost unacceptable level. But if you must be careful on your database size. There is information in Access help on how to link to a picture so I would suggest you look there. Since you have 2 tables be sure you set up your join properly by primary key and foreign key. You can try using the AutoNumber.

Make sure your relationship between the tables is One to Many with Report Table being the One and BirdSp Table being the Many side of the relationship. BirdSp Table should be a subform in the form that is based on Report Table.

hth,

Michael
 
Thanks again for the help. We were able to find away to do it without so much coding. We created a subform to our form. The subform was linked to a query that looked up the value in the combo box and then displayed the picture of our selection in the subform. The code for the query was

SELECT [BirdSpecies].[BirdName], [BirdSpecies].[Picture] AS BirdPhoto, [BirdSpecies].[Species], [BirdSpecies].[BirdType]
FROM BirdSpecies
WHERE ((([BirdSpecies].[BirdName])=[Forms]![WildlifeReports]![BirdSp]));


Where BirdSpecies was a table with all the birdnames and corresponding pictures. BirdName,Picture,Species, and BirdType were fields in the BirdSpecies Table. WildlifeReports was the form with the ComboBox called BirdSp. BirdPhoto is a field name in the query, it is the same as Picture just renamed.

We also created a second query which looked up the BirdName from the BirdSpecies table. We used this query to supply the values for the combo box BirdSp in our form, WildlifeReports.

In the BirdSpecies table, we inserted Bitmap images into the Pictures field. I have also gotten it to work with inserted JPEGs.

I can't explain the reasoning for the second query as I did not come to the solution myself but it works.

One last thing. In the module we added this bit of code:

Private Sub BirdSp_AfterUpdate()

Forms![WildlifeReports]![SubfrmPic].Form.Requery


End Sub


Where BirdSp is the name of the combo box in the form WildlifeReports. SubfrmPic is the subform in WildlifeReports.

I hope this helps anyone else trying to get a corresponding picture to appear in the same form after selecting from a combo box.


Jamie
 

Users who are viewing this thread

Back
Top Bottom