CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: listbox

  1. #1
    Join Date
    May 2001
    Location
    MO, USA
    Posts
    87

    listbox

    i have a listbox connected to a field in my database.....i have 5 textbox's...when the user selects from the list box i would like the textbox's to fill with corresponding info from fields in the same table and database...can this be done or am i reaching for the stars....

    midnightservice


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: listbox

    Of course can this be done. Depending on how you bound your textboxes to the fields in the database. This assumes that the controls are bound via the datasource and datafield properties:

    private Sub SearchDAO()

    If List1.Text <> "" then
    Data1.Recordset.FindFirst "Searchfield='" & list1.Text & "'"
    End If

    End Sub

    private Sub SearchADO()

    If List1.Text <> "" then
    Data1.Recordset.MoveFirst
    Data1.Recordset.Find "Searchfield='" & list1.Text & "'"
    End If

    End Sub




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    May 2001
    Location
    MO, USA
    Posts
    87

    Re: listbox

    okay how does this help me update my text box's.... listbox is field 1 and txtbox1 is field 2 txtbox2 is field3 and so on...so when the user clicks on a choice in the list box the text box's refresh and up date themself according to the database.


    thanx
    midnightservice


  4. #4
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: listbox

    try this

    private Sub Listbox1_Click()
    If List1.Text <> "" then
    rst.MoveFirst
    rst.Find "Searchfield='" & list1.Text & "'"
    If not(rst.eof) then
    txtBox1.Text = rst("Field2")
    txtBox2.Text = rst("Field3")
    End iF
    End If
    End Sub




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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

Featured