Combo Box values problem

Hi,

I have a table named department having fields (deptID, deptName)....I am trying to get the all deptName from department into combobox......but I also want to insert deptID into another table named employee whenever I select a particular deptName from combobox..its related deptID should be entered in employee table...but I don't know the way how to do it as I have deptName in combo box but not deptID..

can anyone help me
[450 byte] By [sobeel] at [2007-11-19 19:55:44]
# 1 Re: Combo Box values problem
Dear Sobeel,

You have to use Datacombobox for showing all the values present
in the database DeptName table from department database.

You can get the Datacombobox from the Components after including
Windows Common Controls -2.

For going into Cmponents, you have to just press shortcut key "Ctrl + T ".

After adding the datacombobox on your form, you have to use ADODC
for connectiing that datacombobox to the DeptName table.

Take Care.

Luv
-@sh!k
ashik143 at 2007-11-9 20:10:51 >
# 2 Re: Combo Box values problem
Hi,
I don't have in this particular moment Visual Studio 6 installed on this computer, so , sorry I can't give you an exact example.But I hope I can help you anyway.

In combobox you set as a bound column deptId and as a ListField DeptName
when you select an deptname from Combo, you also have the DeptId associated to it.(I think the property is called BoundText, you have to search that). You can obtain it on SelectedIndex_Change event of the combobox.
Now, you can hold trhe selected index's deptId, store it in an variable and insert it where you want to.
Daniela
DanielaTm at 2007-11-9 20:11:55 >
# 3 Re: Combo Box values problem
Dear DanielaTm

I have looked for that property but I didn't find any...can u explain me...

Thanks...
sobeel at 2007-11-9 20:12:57 >
# 4 Re: Combo Box values problem
Hi,
I don't have in this particular moment Visual Studio 6 installed on this computer, so , sorry I can't give you an exact example.But I hope I can help you anyway.

In combobox you set as a bound column deptId and as a ListField DeptName
when you select an deptname from Combo, you also have the DeptId associated to it.(I think the property is called BoundText, you have to search that). You can obtain it on SelectedIndex_Change event of the combobox.
Now, you can hold trhe selected index's deptId, store it in an variable and insert it where you want to.
Daniela
Aren't you thinking about Visual Basic.NET ;)
HanneSThEGreaT at 2007-11-9 20:14:03 >
# 5 Re: Combo Box values problem
hi sobeel!!
to do this you can do one more thing:
you can write 2 functions in which you can populate the names of your departments with the department id's and when you select the name and save it, it will save the dept id not the name.
if you r not able do let me know, I'll try to provide you the codes.
Properties that you have to use of combo box are listindex and itemdata.

Take Care
pranay at 2007-11-9 20:14:56 >
# 6 Re: Combo Box values problem
I have a table named department having fields (deptID, deptName)....I am trying to get the all deptName from department into combobox......but I also want to insert deptID into another table named employee whenever I select a particular deptName from combobox..its related deptID should be entered in employee table...but I don't know the way how to do it as I have deptName in combo box but not deptID..
I know what do you mean. Use the Collection for solving your problem.
zmyint at 2007-11-9 20:15:55 >
# 7 Re: Combo Box values problem
hi sobeel!!
to do this you can do one more thing:
you can write 2 functions in which you can populate the names of your departments with the department id's and when you select the name and save it, it will save the dept id not the name.
if you r not able do let me know, I'll try to provide you the codes.
Properties that you have to use of combo box are listindex and itemdata.

Take Care

Dear Pranay...

I have tried it...but couldn't do it...so please help me and provide me the code
sobeel at 2007-11-9 20:17:03 >
# 8 Re: Combo Box values problem
Public Sub AddDataInCombo(ComboName As ComboBox, RsLocal As Recordset, TextData As Integer, Optional ComboItemData As Integer = -1)
Rem this function is to add the data in ur combobox after fetching the data from database with ur id.
If RsLocal.State = adStateClosed Then Exit Sub
With ComboName
.Clear
If RsLocal.RecordCount <> 0 Then
Do Until RsLocal.EOF
.AddItem RsLocal(TextData)
If ComboItemData <> -1 Then
.ItemData(.NewIndex) = Val(RsLocal(ComboItemData))
End If
RsLocal.MoveNext
Loop
End If
End With
End Sub

you have to use this funciton for data population in combo.

while saving the value you have to use the listindex and itemdata value of ur combo. and it will save the id of department not the name of it.

Hope it helps!!
Take Care!!
pranay at 2007-11-9 20:17:58 >
# 9 Re: Combo Box values problem
hi,
write the following code to get the dept id and name

select to_char(deptID) || '-' || deptName as Department from Dept

then, when you save the employee details, and the dept id that is selected from the combo.

do like this...

use left$() to get the 1st characters till the - using combo1.text.

use the id as the dept id.

Regards
VB_Learner at 2007-11-9 20:19:01 >
# 10 Re: Combo Box values problem
Hi,
Yes, I I confused that.It was an solution, but when you used DataCombo, component available when including as a project reference Microsoft Activex DataObject Library 2..., not the simple combobox. I don't know your project, but you might consider use DataCombo.
Daniela
DanielaTm at 2007-11-9 20:20:04 >