CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2001
    Posts
    20

    How would you all do this?

    Problem description: I need to load a record based on an alphanumeric primary key field of a table selected from a dropdown combo box. Then, i need a command button that when clicked, will display the record in the approriate text boxes. For example, the user will select a project number (alphanumeric) from a project table using a datacombo box. then, all the text boxes will populate with the appropriate fields from the table. I've tried numerous ways to do this to no avail. I'm a beginner at this so i would appreciate any help i can get. Thanks in advance.


  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: How would you all do this?

    The combobox has a Click event. in there, grab what was selected (Combo1.List(Combo1.ListIndex)) will return to the text of the chosen. Now issue your SQL statement with this value as the WHERE clause. Once you get your recordset back - assign the text boxes their respective values.

    if you need more detail - let me know.

    john

    John Pirkey
    MCSD
    http://www.ShallowWaterSystems.com
    http://www.stlvbug.org
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Join Date
    Apr 2001
    Posts
    20

    Re: How would you all do this?

    Thanks for your reply Johnny. I've tried that, and I got errors, but I think my problem is that i'm trying to use ADO and haven't fully grasped the concept such as opening connections and stuff like that. So what i guess i'm saying is yes I do need more detail. Thanks again.


  4. #4
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: How would you all do this?

    well, something like this:

    private Sub Combo1_Click()
    dim sql as string
    dim rs as adodb.recordset

    sql = "SELECT * FROM YourTable WHERE ProductNumber = '" & Combo1.List(Combo1.Listindex) & "'" '

    set rs = new adodb.recordset

    set rs = YourConnectionObject.Execute(sql)

    if not rs.eof then
    txtProductName.Text = rs!ProductName
    txtProductCode.Text = rs!ProductCode
    txtProductPrice.Text = rs!ProductPrice

    rs.close
    end if

    set rs = nothing
    End Sub




    something like that shoud work for what you want.

    hope this helps,

    john

    John Pirkey
    MCSD
    http://www.ShallowWaterSystems.com
    http://www.stlvbug.org
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  5. #5
    Join Date
    Apr 2001
    Posts
    20

    Re: How would you all do this?

    thanks , I will try it. Let you know what happens!


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