renjith
asked on
selecting a value from combo box
Knowing only the Item Data for a combo box how can I make the corresponding value for that Item Data selected ?
regards
renjith
regards
renjith
Besides the fact that i don't use the DataCombo (maybe wrong attitude :-) i suggest that you have a collection with the itemdata as key and the Listindex values as data. This will allow you to move very fast to the required item...
Otherwise you have too loop through the items and compare the ItemData values...
Cheers
Otherwise you have too loop through the items and compare the ItemData values...
Cheers
angelllll -
If you set the combobox style to 2 - dropdown list, then you can set the combobox text to the data and it will focus automatically (and quickly) on the correct row, and you will be able to get the correct listindex property.
If you set the combobox style to 2 - dropdown list, then you can set the combobox text to the data and it will focus automatically (and quickly) on the correct row, and you will be able to get the correct listindex property.
Of course, but as renjiht said, he has the ItemData value, which is typically the Key value... and not the text value...
CHeers
CHeers
ASKER
angell, i couldn't follow the first response you posted. This is the problem. Iam having member Information in a table. The department etc are stored as ids(integers) in this table. So in the form when i choose a member i want the other details like department etc to be populated.
I have the department names in a combo box and ItemData is the department-ids. so depending upon the member name selected iam getting the corresp: dept-id from table. Now i need to make the dept name with that dept-id as the itemdata 'selected'. the dept names can be duplicates thatz why i want to do the selection based on dept-id.
i'll stop this short story.
regards
renjith
I have the department names in a combo box and ItemData is the department-ids. so depending upon the member name selected iam getting the corresp: dept-id from table. Now i need to make the dept name with that dept-id as the itemdata 'selected'. the dept names can be duplicates thatz why i want to do the selection based on dept-id.
i'll stop this short story.
regards
renjith
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think the simplest solution would be to do a DepartmentName query, based on the Department ID (already known from the Person).
set rsDeptName = db.openrecordset("Select DeptName from Departments where DepartmentID =" & DeptID)
cboDepartment.Text = rsDeptName!DeptName
set rsDeptName = db.openrecordset("Select DeptName from Departments where DepartmentID =" & DeptID)
cboDepartment.Text = rsDeptName!DeptName
simplest <> most effective
ASKER
That is simplest but there can be duplicate department names. After the values get populated iam again updating the table. So i want the right Ids :)
regards
renjith
regards
renjith
I would recommend filling the combobox controls with unique data (people and departments).
Hint: "Select Distinct ..." SQL statement
Hint: "Select Distinct ..." SQL statement
.ListIndex property.