[RESOLVED] Autofill a textbox based on the value in combobox.
Hi everyone,
I'm designing a student database in VB 6. I used MS Access to store the tables. I've a table with studentID which is unique and other student details like FirstName, LastName and such. I populated a combobox with all the studentID's. Now I've to fill the textboxes automatically with the rest of the details(relevant to the studentID) from the other fields in the table. I've been trying hard to get this working for awhile now but with no luck. I've searched the forums but havent found anything specific to my need. Thanks in advance. :)
Re: Autofill a textbox based on the value in combobox.
Welcome to the forums. :wave:
How are you connecting to your database? Are you using a data control? (I hope not) or programming code (I hope)
Re: Autofill a textbox based on the value in combobox.
I'm doing it in code. Have had some bad experience with data controls in the past :P
Re: Autofill a textbox based on the value in combobox.
define a database object and recordset but first you have to add the ADO refrence
Re: Autofill a textbox based on the value in combobox.
This example presumes you are using ADO.
vb Code:
Dim sSQL As String
Set rs = New ADODB.Recordset
sSQL = "SELECT firstname, lastname, what_ever_else_you_need FROM yourtable "
sSQL = sSQL & "WHERE studentId = '" & txtStudentId.Text & "' "
rs.Open sSQL, cn
txtFName.Text = rs.Fields.Item("firstname").Value
txtLName.Text = rs.Fields.Item("lastname").Value
'etc
rs.Close
Set rs = Nothing
Replace rs with your recordset object. Replace cn with your connection object. Replace the name of the textboxs with the textbox names you are using.
Re: Autofill a textbox based on the value in combobox.
Quote:
Originally Posted by avrail
define a database object and recordset but first you have to add the ADO refrence
DAO uses a database object. ADO uses a connection object. :)
Re: Autofill a textbox based on the value in combobox.
Hack.. That totally worked. Awesome man. :)