|
-
Nov 7th, 2001, 10:02 AM
#1
Thread Starter
New Member
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.
-
Nov 8th, 2001, 03:52 AM
#2
Hyperactive Member
VB Code:
private sub form_load()
dim recSelection as ADODB.recordset
set recSelection = new ADODB.Recordset
'this opens the desired record
recSelection.open "select YourField from YourTable", YourConnection, adOpenDynamic,adLockOptimistic
'clear the combobox and populate
YourCombo.clear
recSelection.movefirst
do while not recSelection.EOF
YourCombo.AddItem recSelection.Fields("YourField").value
loop
If your combobox is populated and the user makes a selection:
VB Code:
private sub YourCombo_click()
dim recNewValues as ADODB.recordset
set recNewValues = new ADODB.Recordset
'this opens the desired record
recNewValues.open "select * from YourTable where Yourfield = '" & YourCombo.text & "'", YourConnection, adOpenDynamic,adLockOptimistic
'populate the textboxes
Text1.text = recNewValues.fields("Field1").value
Text2.text = recNewValues.fields("Field2").value
'disconnect recordset
set recNewValues = nothing
end sub
-
Nov 8th, 2001, 04:24 AM
#3
Checkout the zip samples here ...
Although this uses VBA / Excel, the combobox code is the same as in VB.
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
|