Results 1 to 7 of 7

Thread: [RESOLVED] Autofill a textbox based on the value in combobox.

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    12

    Resolved [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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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)

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    12

    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

  4. #4
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    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

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Autofill a textbox based on the value in combobox.

    This example presumes you are using ADO.
    vb Code:
    1. Dim sSQL As String
    2. Set rs = New ADODB.Recordset
    3.  
    4. sSQL = "SELECT firstname, lastname, what_ever_else_you_need FROM yourtable "
    5. sSQL = sSQL & "WHERE studentId = '" & txtStudentId.Text & "' "
    6. rs.Open sSQL, cn
    7. txtFName.Text = rs.Fields.Item("firstname").Value
    8. txtLName.Text = rs.Fields.Item("lastname").Value
    9. 'etc
    10. rs.Close
    11. 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.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    12

    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
  •  



Click Here to Expand Forum to Full Width