Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataComoboBox /Requery the rest of the controls on the form using ADO

Status
Not open for further replies.

SkyHigh

Technical User
May 30, 2002
309
CA
Hi
I have to create a form in VB6 with a Data Combobox ( that part I have picked up from the FAQ), what I need to do is when a value is selected from the combobox the rest of controls on the form should be requeried on the basis of new value selected in the combo box.

The data for the combo box and the rest of the controls will be querying just one table using ADO - please help with code or if there are any samples available that will be great

Thanks much for your help.

 
I tried the example given in the FAQ to populate the dbcombobox using the following example which results in run-time error 91 i.e. "Object variable or with block variable not set", please let me know if I am missing something conn1 is the globale connection which is working fine and has been tested with other routines, thanks alot fo your help.

Private Sub Form_Load()

Dim oRs As New ADODB.Recordset
Dim strSQL As String
strSQL = "SELECT id, login FROM tblusers"
Call openconn
oRs.Open strSQL, conn1, adOpenForwardOnly
Set DBCombo1.RowSource = oRs
DBCombo1.ListField = oRs.Fields("login").Name
DBCombo1.BoundColumn = oRs.Fields("id").Name

end Sub

 
Here's another part of what I am trying to achieve, I added this routine on the change event of datacombo1 and typed in the value manully and resulted in "Syntax error at the end of input at character 118", so I have now both the pieces to make things the way I want it to work but the parts are not working please help - thanks much.

Private Sub DataCombo1_Change()
Call openconn
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open "select id,login,fname,lname,title from tblusers where id = " & Me.DataCombo1.BoundText, conn1, adOpenStatic, adLockOptimistic

Dim oText As TextBox
'Bind the text boxes to the data provider
For Each oText In Me.txtFields
Set oText.DataSource = adoPrimaryRS
Next

mbDataChanged = False
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top