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

Setting Combobox Selected Index 2

Status
Not open for further replies.

devRyan

Programmer
Sep 1, 2006
104
US
Hi All,

I have a form that contains a combobox dropdown for which I want to programmatically set the selected index. I've dug through the combobox properties and found no SelectedIndex, but have found the ListIndex, though whenever I try to set the ListIndex I get errors.

What I have is a form that lists information from one of the tables in my db, but for each record in the db, only the employeeID is kept. Since that doesn't really help the user, I've had to populate the list using a separate query that brings back "LName, FName", but I need the dropdown to select the proper name in relation to the ID in the db. I'm trying to do this in the Form_Current event, but so far no luck.

Any ideas on how to do this, or other methods of displaying the names in the dropdown and have them selected in reference to the foriegn key kept in the table?

Thanks.

devRyan
 
Set the BoundColumn of the combo to the ID.
Then, in the Current event procedure, simply set the Value of the combo.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Perhaps I should elaborate.

I have 3 tables used to track training.
Courses, Employees, lnkCE.

lnkCE serves as the linking table for each record of training, with the columns, lnkCEID(PK), CourseID(FK), EmpID(FK), DateCompleted, HoursTrained.

My form is simple an output of this table where each row can be worked on individually, but instead of displaying the CourseID and EmployeeID, as text fields, I need to provide dropdowns with all the respective Courses and Employees, with the current IDs selected on load.

This means I have to load the dropdowns from separate queries then that which loads the basic record information.
I've still got access to the Course and Emp IDs, and I can get the dropdowns to load the needed text descriptions, though I am having some problems getting the designer to recognize my key fields, but that's not my primary concern, since I can't even get this to work with just the key values.
 
This is what PHV is saying. Assume lnkCE holds course and employer keys something like

empID CrsID date Hours
1 5
1 7
2 5

now on your employer combo you will have something like empID, EmpName, ...

EmpID EmpName
1 Intel
2 Exxon

To show the name bind the control to empID of tblLnk, but set the controls values as
bound column: 1
column count: 2
column widths: 0;"1"

When you select "Intel" from this combo it will put 1 into the table lnkCE, but show "Intel". Also if the value is 1 you will see "Intel
 
Ok, I see now.

Simple, once you know it. ;)

Thanks guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top