DataCombo box not moving through recordset
Hi,
I am new to database programming in vb6. I have table which have 2 fields: Cus_code and Cus_name. I have successfully populated the data combo boxes: combo_cuscode and combo_cusname. But what i want to do now is to move through the recordset using datacombo boxes. For example: If i select customer code from combo_cuscode, it should go to that recordset, so that the other datacombo box combo_cusname display the correct customer name for the customer code i selected in the combo_cuscode. What happens now is that the data in the current recordset is trying to change when i select a entry from the combo box and generate error as it is the primary key field. Please help me out to solve my issue with the data combo box.
Thanking you,
Mani
[773 byte] By [
manibalraj] at [2007-11-20 7:29:32]

# 1 Re: DataCombo box not moving through recordset
First of all use combo box and DO NOT USE datacombo(my suggestion because of personal experience. Although I am not an expert)
Now populate your first combobox which i will name as combo_custcode as below
Also I assume that you have stored the code as string
If MyRs.State = adStateOpen Then MyRs.Close
MyRs.Open "select distinct(code) from customerdetails", MyCon, adOpenForwardOnly, adLockOptimistic
If MyRs.BOF = False Then
Do Until MyRs.EOF
combo_cuscode.AddItem (Str(MyRs("pid")))
MyRs.MoveNext
Loop
Else
MsgBox "No records yet"
End If
Now in the combo_cuscode keyup event write down
One more suggestion You are going to display the name. In that case why are you using combo, you can use text box or label
If KeyCode = vbKeyReturn Then
If combo_cuscode.Text = "" Then
MsgBox "select records"
Exit Sub
End If
Else
MyRs.Open "select * from customerdetails where code=" & (Trim(cbMOD.Text)), MyCon, adOpenDynamic, adLockOptimistic
txtNAME.Text = Trim(MyRs("name"))
MyRs.Close
End If
In case you want combobox change txtNAME to combo box
Next time onwards while posting also post your code