Link to home
Start Free TrialLog in
Avatar of vmccune
vmccuneFlag for United States of America

asked on

Display Ole from combo box

I have what I think is a simple requirement.  I have two tables tblPics and tblClients.  I want from the client form to be able to select a name of a Pic , red house, blue house, and have the picture of the red house/blue house appear in the picture box.  The client does not want to link and if I imbed, the bloat is enourmouse.  I might have many clients that will select red house and I want to have the red house pic display on each client that has selected red house from a combo box of house types.


Thanks,

Vince
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

What data are you storing exactly in tblPics?
Avatar of vmccune

ASKER

tblpics has two fields, HouseName and Picture.
Use an Image control and not an OLE control. Assuming the picture field is a filename, all you need to do is make your combo box select both fields from tblpics, and, if the picture is in the second column, you can use some code like this in the AfterUpdate event of the combo:

Me!MyImageControl.Picture=Me!MyComboBox.Column(1)
Avatar of vmccune

ASKER

picture field is NOT a file name,  It is the actual picture stored into an Ole field.
Well, assuming you don't want to store OLE objects in your database, look at the link that capricorn1 posted.
Avatar of vmccune

ASKER

also,  I dont want to store the picture on each record as many records will have the same picture.  Basically I wnat it to work as if I had an employee ID field that had ID,Fname,Lname and then had to additional text boxes to display the firat and last name like EmpID.Column(1) and EmpID.Column(2) respectively.  I just wnat the pic to reference and display without writing to the record.  The rub is that the data in the access table already so linking is not an option.

ASKER CERTIFIED SOLUTION
Avatar of shanesuebsahakarn
shanesuebsahakarn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vmccune

ASKER

Thanks so far.

Dim rst As DAO.Recordset

This line gives the error:

Compile Error:
User-Define type not defined.

any thoughts ?
You haven't got the DAO libray referenced (this is not included as default in A2K onwards), but it's easy enough to sort out - in the VBA window, click Tools->References and check "Microsoft DAO 3.6" (or 3.5 if that's the only one available).
Avatar of vmccune

ASKER

Me!Picture!OleData = Rst!Picture.GetChunk(Rst!Picture.Size)

Gives "Argument not optional"  

Maybe I misnamed something.  What are the two "Picture"'s referencing ?

Thanks.
The second ! needs to be a ., as in:

Me!Picture.OleData = Rst!Picture.GetChunk(Rst!Picture.Size)

The first Picture should be replaced with the name of the unbound OLE frame on your form that is being used to display the picture. The second and third Picture should be replaced with the name of the OLE field in your picture table that holds the picture data.
Avatar of vmccune

ASKER

*** RETURNS ARGUMENT NOT OPTIONAL ***


Dim Rst As DAO.Recordset
  Set Rst = CurrentDb.OpenRecordset("select * from emp1 WHERE EmployeeID ='" & Me!Combo & "'")
  Me!Pic.OleData = Rst!Photo.GetChunk(Rst!Photo.Size) ... *** RETURNS ARGUMENT NOT OPTIONAL ***
 
  Rst.Close
  Set Rst = Nothing


table is Emp1
field on form is Pic
field in Emp1 table is Photo
Whoops, the line should read:

Me!Pic.OleData = Rst!Photo.GetChunk(0, Rst!Photo.Size)
Avatar of vmccune

ASKER

DATA TYPE MISMATCH IN EXPRESSION


Set Rst = CurrentDb.OpenRecordset("select * from emp1 WHERE EmployeeID ='" & Me!Combo & "'")
Avatar of vmccune

ASKER

Me!Combo is numeric and equals what was selected in the combo box
Avatar of vmccune

ASKER

RECORDSET DOES NOT SUPPORT THIS METHOD



Dim Rst As DAO.Recordset
  Set Rst = CurrentDb.OpenRecordset("select * from emp1 WHERE EmployeeID =" & Me!Combo)
  '  Set Rst = CurrentDb.OpenRecordset("select * from emp1 WHERE EmployeeID ='" & Me!Combo & "'")
  Me!Pic.OleData = Rst!Photo.GetChunk(0, Rst!Photo.Size) RECORDSET DOES NOT SUPPORT THIS METHOD
 
  Rst.Close
  Set Rst = Nothing
No, the recordset needs to select from the picture table - this statement is selecting the appropriate picture to display in the OLE frame.

The combo box in question should select the picture names from the picture table - it's basically the combo that allows the user to select which picture is to be displayed for the record.
Avatar of vmccune

ASKER

I dont have picture names in the table.  The field Pic in EMp1 is Ole to and says Bitmap Image in the field.  I hope My bad explanation didnt lead us the the right pew in the wrong church.  so to speak
By picture name, I mean the field that identifies the picture you want to show (in this case, I assume it's the HouseName field).

So the combo in question should display a list of house names, and it should be bound to a field that stores the house name in the clients table.
Avatar of vmccune

ASKER

OBJECT DOES NOT SUPPORT THIS PROPERTY OR METHOD  


Dim Rst As DAO.Recordset
  Set Rst = CurrentDb.OpenRecordset("select * from emp1 WHERE EmployeeID =" & Me!Combo)
  '  Set Rst = CurrentDb.OpenRecordset("select * from emp1 WHERE EmployeeID ='" & Me!Combo & "'")
  Me!Pict.OleData = Rst!Photo.GetChunk(0, Rst!Photo.Size)   OBJECT DOES NOT SUPPORT THIS PROPERTY OR METHOD  
 
  Rst.Close
  Set Rst = Nothing
Your statement is still selecting from the the emp1 table. You say you have two tables, tblClient and tblPics. Let's get back to basics and see if we can get an understanding here.

tblPics contains your picture data. This should have two fields:
HouseName - the primary key which uniquely identifies the picture.
Picture - an OLE field containing your picture data.

tblClients contains your client details. This should have a field in it called HouseName. This stores the name of the picture that you want to display for that particular client record - this name matches the HouseName field in the tblPics table.

Is this correct?
Avatar of vmccune

ASKER

 Dim Rst As DAO.Recordset
  Set Rst = CurrentDb.OpenRecordset("select * from Pictbl WHERE PicID =" & Me!ClientID)
  '  Set Rst = CurrentDb.OpenRecordset("select * from emp1 WHERE EmployeeID ='" & Me!Combo & "'")
  Me!Pict.OleData = Rst!Photo.GetChunk(0, Rst!Photo.Size)
 
  Rst.Close
  Set Rst = Nothing

ClientTbl - 1 Field - Autonumber [ClientID]

PicTbl 2 Fields - [PicID] and [Photo]

Form - Emp1
2 fields on the form bound to ClientTbl
[ClientId]
[Pict] - should display the picture
No - ClientTbl should contain a PicID as well. This identifies the picture to use for that client.

Your form should have a combo box bound to the PicID field (let's call it cboPicID). This combo box should select all PicIDs from the PicTbl table. Your Set line then looks something like this:

Set Rst = CurrentDb.OpenRecordset("select * from Pictbl WHERE PicID =" & Me!cboPicID)

So client ID 1 might have PicID 5 stored against it. The code looks up PicID 5 from Pictbl, grabs the data from it and places it in the Pict OLE frame.
Avatar of vmccune

ASKER

The set is working ok

Me!Pict.OleData = Rst!Photo.GetChunk(0, Rst!Photo.Size)

is failing

Pict = Unbound ole field on form

Photo = Ole Picture field in Pictbl

Yes, it will fail because it is not finding a matching record in the Pictbl table.

You *must* store a PicID in the ClientTbl table as well, as I have described. Otherwise you are trying to look up a picID that is the same as the ClientID, and that why the line is failing, because such a PicID may not exist.
Looks almost the same as the product images in the NorthWind.mdb sample database.

The main issue for Access 2000 will be to suppress the database bloat by issuing the latest service packs:
SR1a/2:
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q276367
SR3:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;326585

Nic;o)
Avatar of vmccune

ASKER

 And we have a winner !

  Dim Rst As DAO.Recordset
  Set Rst = CurrentDb.OpenRecordset("select * from Pictbl WHERE PicID =" & Me!ClientID)
  Me.Pict = Rst!Photo
  Rst.Close
  Set Rst = Nothing


Shane,  we we ever so close even with the first go.  The final problem was the getchunk.  I decided to through caution to the wind and look it up.  It only works with copying one Ole or activeX from one point to another.  Not just a reference and display.

Thanks for the long evening.
Cool - I've actually used the GetChunk method and it does work though :)