|
-
Apr 13th, 2007, 12:41 PM
#1
Thread Starter
New Member
[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.
-
Apr 13th, 2007, 12:42 PM
#2
Re: Autofill a textbox based on the value in combobox.
Welcome to the forums. 
How are you connecting to your database? Are you using a data control? (I hope not) or programming code (I hope)
-
Apr 13th, 2007, 12:48 PM
#3
Thread Starter
New Member
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
-
Apr 13th, 2007, 01:21 PM
#4
Frenzied Member
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
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Apr 13th, 2007, 01:23 PM
#5
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.
-
Apr 13th, 2007, 01:24 PM
#6
Re: Autofill a textbox based on the value in combobox.
 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.
-
Apr 13th, 2007, 01:38 PM
#7
Thread Starter
New Member
Re: Autofill a textbox based on the value in combobox.
Hack.. That totally worked. Awesome man.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|