Click to See Complete Forum and Search --> : Changing Recordsource at run-time


Nihita Goel
April 12th, 2001, 06:51 AM
This is about DataGrid and ADO Control.
I have set RecordSource and datasource property at design time.
However I want to change the RecordSource at run time also.
Say My Screen is showing sales plan of a particular product. I have a ComboBox on screen and I want that as soon as user selects a product the datagrid should be populated by sales plan of that product. This is how I have implemented it.

Private Sub cbProduct_Validate(Cancel As Boolean)

Dim prod_table As String
prod_table = cbProduct.Text & "_SP"
sqlstr = "select * from " & prod_table & " order by warehouse_id "
rs.Close
rs.Open (sqlstr)
Set Adodc1.Recordset = rs
DataGrid1.Refresh

End Sub

But this is not working. Can you tell me what the problem is ?

wmacleod
April 12th, 2001, 09:56 AM
You need to refresh your data control

'adodc1.refresh' after changing the recordset

Nihita Goel
April 13th, 2001, 12:21 AM
I tried doing Adodc1.Refresh also. What is happening is I am getting zero records in the data grid after changing the recordset.
Anything else that I am missing ?

Nihita Goel
April 13th, 2001, 05:56 AM
This is how it has worked finally :

sql = "Select ......"
Adodc1.RecordSource = sql
Adodc1.Refresh