I would like to somehow put the link to the picture in a field in a table, and then have the picture change depending on the record I am viewing (which is altered by the combo box pertaining to another field) ok thanks!
Private Sub cboSamID_AfterUpdate()
[Forms]!fSampleView.Requery
imgSample.Picture = [tSample]![SamPhoto]
End Sub
That is what i have where cbuSamID contains a list of the record ID's
but i keep getting this error
"Run time Error '2456'
Customer Info System can't find the field 'tSample' referred to in your expression"
But what i don't get is I used the "build..." thing to get [tSample]![SamPhoto]....
I need a cleaner way of getting the path from my field... The code works when i put imgSample.Picture = "filename" but i need it to reference the field.. i tried making a query and referencing the field from there so that only one record was in the query (criteria being the combo box) but that produced the same error please help
Help pls ?
I'm not sure why you have the ID field twice but... imgSample.Picture = Me.cboSamID.Column(n)
...where n is the zero based column index of the column with the path in it. How many fields are in the tSample table?
If the path is in the 3rd column then the code would be:
imgSample.Picture = Me.cboSamID.Column(2)
On the data tab of the properties sheet for the cbo press the "..." button on the RowSource row. That brings up the Query builder. Go to the DataSheet mode of the query and find out which column has the FileName in it. Subsitute that (column-1) for n in the code I supplied. Does that work?
I have made up a "testing DB" for now and this is what i currently have:
Sub Combo4_AfterUpdate()
' Find the record that matches the control.
Me.RecordsetClone.FindFirst "[ID] = " & Me![Combo4]
Me.Bookmark = Me.RecordsetClone.Bookmark
'imgBoom.Picture = "Z:\CustInfo\SamplePhotos\Sample4.jpg"
imgBoom.Picture = Me.[Combo4].Column(1)
End Sub
Rowsource for the combo box:
SELECT DISTINCTROW tData.ID, tData.Image FROM tData;
Control source for the form:
tData
So my tData.Image should be my (1) column correct ?
That should be correct. How about putting in a diagnostic MsgBox? MsgBox "Show picture at [" & Me.Combo4.Column(1) & "]"
imgBoom.Picture = Me.Combo4.Column(1)
That should at least show you what is in the field.
the msg box says "show picture at []"
when i check column(0) it says "show picture at [That record's ID]" so i know its picking that up ... so why is it picking null up for the other fields... i even tried filling in every record with something.. and setting the default text to " " but it still picks up a NPE (null pointer)
ID |Comment| |List1ID | List2ID | Image
---------------------------------------------------------------------
2 |Comment for Data ID 2 |2 |3 |Z:\CustInfo\SamplePhotos\S....
3 |Comment for Data ID 3 |3 |2 |asdfdasfa
4 |Comment for Data ID 4 |1 |1 |asdffasfasdf
5 |Comment for Data ID 5 |2 |1 |asdfdfasdfasdf
(Auto#)
Go to the Format tab of the properties sheet for the ComboBox and change the ColumnCount to 2. Then set the Column Widths to 0";1"
The code to use is: imgSample.Picture = Me.Combo4.Column(1) for the sample you sent.
Now that I solved that... The next thing i need is the ability to add pictures... but i want the users to be able to browse for the filepath rather than have to type it in themselves... is there a way to browse the contents of the computer through some method/object etc ?