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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combobox or datacombo lookup ??

Status
Not open for further replies.

dciadmin

IS-IT--Management
May 10, 2002
34
Used Access to create two tables that are linked ... the item table and the tool table. The item table has a field called toolid which is linked to the tool table with a field called toolid ...

In VB6 I have a datagrid that when a row is selected, all of my bound boxes to the item table are updated according to their linked field. I want to have a combobox or datacombobox that is linked to both of the tables ... the combobox is driven by the toolid in the item database but when the dropdown is clicked it will show the actual toolname field from the tool table instead of the toolid.

I want to be able to click through the datagrid and have the toolname show for each record even though it is in another database. Basically the same way a Lookup works in Access.

Any sample code on how to do that? I understand that there is a way using VB.NET ... something about displaymember, etc. ... but I only have VB6.

Any insight is appreciated ..

JL
 
I don't understand why you're using a combo box if there's only one toolname for each row. I'd just use a label. If there are multiple toolnames for each row, and you want the user to be able to select one of them or something, that might make sense to me.

In order to do that, I would populate the List property with the toolnames, and the ItemData property with the toolids, assuming that your toolid is an integer. If the id has alpha characters, put all the id's in an array, and use the offsets of the array in the itemdata property.

When the user makes a selection (click event), the ItemData property of the selected item will evaluate to the toolid of same.

Basic technique to add items in this way is:

Code:
With MyList
   .AddItem myRs!toolname
   .List(.NewIndex).ItemData = myRs!toolid
End With

This code is contained in a do block that iterates through your recordset.
 
Hi Bob,

Thanks for replying. I hit upon the itemdata concept after I posted. The basic concept I am trying is this ... I have a portion of the form that shows the user the details for an item using bound text boxes to the item database. One of the details for the item is what tool is going to be used with that item (the user has a choice) and that is kept as the toolid inside the item database. When the user chooses an item, I want the toolid to get the actual toolname from the tool database and show that on the form instead inside the combobox. Then as the user clicks thru the items in a datagrid, all the bound text boxes update as well as the combobox text for that record. When the user adds or edits the item details he should be able to just dropdown the combo and choose a toolname and have the toolid from the tool database write to the toolid for the item database. Does that make more sense?

Got the combobox to fill using the itemdata ... but then had trouble with getting the combobox text to show the toolname. Couldn't just set the combobox text to the itemdata listindex as I thought. This is my first database program with VB so I expect my problem is simply some oversight somewhere.

Code is fun to write but oh how frustrating it can be to get stuck on what I know is simple stuff :) Thanks for the help,

JL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top