rickkcir
Technical User
- Jul 31, 2002
- 35
I am having trouble populating a datacombo box. I have two datacombo boxes, datacombo1 & datacombo2. Datacombo2's data is based on what is chosen in datacombo1. I have made the recordset, but now I need to get the datacombo box filled with the recordset. How do I fill datacombo2 with the data that I just got out of the table using the sql statement? Thanks for any help!
Here is the code I am using:
Private Sub DataCombo1_Change()
Dim sql As String
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
Dim rs As ADODB.Recordset
Dim selection As String
selection = Me.DataCombo1
Set rs = New ADODB.Recordset
cnn.CursorLocation = adUseClient
cnn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Rick\VB Project\Reports.mdb;Persist Security Info=False"
sql = "Select Subcategory from tbl_SubCategory where Category = ' " & selection & " ';"
rs.Open sql, cnn, , adLockOptimistic
End Sub
Here is the code I am using:
Private Sub DataCombo1_Change()
Dim sql As String
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
Dim rs As ADODB.Recordset
Dim selection As String
selection = Me.DataCombo1
Set rs = New ADODB.Recordset
cnn.CursorLocation = adUseClient
cnn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Rick\VB Project\Reports.mdb;Persist Security Info=False"
sql = "Select Subcategory from tbl_SubCategory where Category = ' " & selection & " ';"
rs.Open sql, cnn, , adLockOptimistic
End Sub