Results 1 to 3 of 3

Thread: Navigating data using a combo

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    1

    Navigating data using a combo

    I'm developing a VB app that uses data from an Access table and run into a problem.

    I'm used to working in VFP where a bound combo will move the record pointer in the table when you select a value from it's list. In my app, I have a dropdown combo and several text fields. the user selects a value from the combo (the list is populated by field values from the table) and the text boxes (which are bound to the other fields in the table) should then update to show the data from the selected record. In VB this just does not happen, even with the so called "data" controls! They control squat as far as I can tell!

    I've got to the stage where I know *what* to do, but not *how* to do it - I have to reposition the record pointer programatically on the combo change event so the text fields update. Can anyone help?

    Oh and I'm using an ADO dc on the form, I've also tried using the data environment (I like the concept of that!) and use the data combo control.

  2. #2
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322
    VB Code:
    1. private sub form_load()
    2.  
    3. dim recSelection as ADODB.recordset
    4.  
    5. set recSelection = new ADODB.Recordset
    6.  
    7. 'this opens the desired record
    8. recSelection.open "select YourField from YourTable", YourConnection, adOpenDynamic,adLockOptimistic
    9.  
    10. 'clear the combobox and populate
    11. YourCombo.clear
    12.  
    13. recSelection.movefirst
    14. do while not recSelection.EOF
    15. YourCombo.AddItem recSelection.Fields("YourField").value
    16. loop

    If your combobox is populated and the user makes a selection:

    VB Code:
    1. private sub YourCombo_click()
    2.  
    3. dim recNewValues as ADODB.recordset
    4.  
    5. set recNewValues = new ADODB.Recordset
    6.  
    7. 'this opens the desired record
    8. recNewValues.open "select * from YourTable where Yourfield = '" & YourCombo.text & "'", YourConnection, adOpenDynamic,adLockOptimistic
    9.  
    10. 'populate the textboxes
    11. Text1.text = recNewValues.fields("Field1").value
    12. Text2.text = recNewValues.fields("Field2").value
    13.  
    14. 'disconnect recordset
    15. set recNewValues = nothing
    16.  
    17. end sub

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Checkout the zip samples here ...
    Although this uses VBA / Excel, the combobox code is the same as in VB.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

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