[VB6] Combo Box (Dropdown List)
Hi! I just wanna ask regarding this one...
I have a dropdown list, where in it is empty, it only gets it's data from my database. Preloading is fine and the dropdownl list is displaying all of the data from the table that I selected. Now what I wanted is I want to get the value of the item that is selected. My question is, how can I pass to the variable the thing that is selected?
I tried doing this but It is not working:
Code:
Private Sub cboEID_Click()
strEID = cboEID
End Sub
Hope you can help me... Thanks!!
Re: [VB6] Combo Box (Dropdown List)
You have to add values to the dropdown list first, and that code hasn't added any.
Re: [VB6] Combo Box (Dropdown List)
Values for the dropdownlist is from here:
Code:
Private Sub Form_Load()
Dim strSQL As String
strSQL = "select Eid from Employee order by Eid"
Set RS = New ADODB.Recordset
Set Con = New ADODB.Connection
Con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Attendance.accdb;Persist Security Info=False;"
Con.Open
RS.Open strSQL, Con, adOpenKeyset, adLockOptimistic
RS.MoveFirst
Do While Not RS.EOF
cboEID.AddItem RS!Eid
RS.MoveNext
Loop
RS.Close
End Sub
Re: [VB6] Combo Box (Dropdown List)
So in the area for the dropdown list, try something like:
Code:
textBox1.text = cboEID.Eid
or something similar to that. I haven't programmed in VB6 for ages, so I apologise if this is completely wrong. I'm sure it's something along those lines though, I distinctively remember doing something similar to this. :tongue:
Re: [VB6] Combo Box (Dropdown List)
Hmmmm...
It didnt work...
Hmmm... How can I get the value of the selected Item @ the dropdown list?
Cuz I just want to get the selected item and use it as a primary key to search for @ the database...
So when I get value of selected item, this code will be generating the values for the textbox fields:
Code:
Private Sub cmdSubLoad_Click()
Dim strSQL, strSQL2, strSQL3 As String
Dim vbAns As String
strSQL = "select Eid from Employee order by Eid"
strSQL2 = "select * from Employee"
strSQL3 = "select * from LogIn"
strPass = UpdateRec.txtPass.Text
strName = UpdateRec.txtName.Text
strNick = UpdateRec.txtNick.Text
strPos = UpdateRec.txtPosition.Text
strContact = UpdateRec.txtContact.Text
strTitle = UpdateRec.txtTitleDisp.Text
strPlate = UpdateRec.txtPlate.Text
strModel = UpdateRec.txtModel.Text
strAdd = UpdateRec.txtAddress.Text
strBday = UpdateRec.txtBdayDisp.Text
Set RS = New ADODB.Recordset
Set Con = New ADODB.Connection
Con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Attendance.accdb;Persist Security Info=False;"
Con.Open
RS.Open strSQL3, Con, adOpenKeyset, adLockOptimistic
RS.Find "Eid='" & strEID & "'"
If (RS.BOF = False) Or (RS.EOF = False) Then
strPass = RS.Fields!Password
End If
RS.Close
RS.Open strSQL2, Con, adOpenKeyset, adLockOptimistic
RS.Find "Eid='" & strEID & "'"
If (RS.BOF = False) Or (RS.EOF = False) Then
strName = RS.Fields!Name
strNick = RS.Fields!Nickname
strPos = RS.Fields!Position
strTitle = RS.Fields!Title
strBday = RS.Fields!Birthdate
strContact = RS.Fields!ContactNumber
strPlate = RS.Fields!PlateNumber
strModel = RS.Fields!CarModel
strAdd = RS.Fields!Address
End If
RS.Close
End Sub
Re: [VB6] Combo Box (Dropdown List)
*BUMP*
Any idea?
***EDIT***
Got it to work now...
Realized what I've been doing wrong.
Thanks Hammad for the help!