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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

refreshing a msflexgrid 1

Status
Not open for further replies.

techie99

Programmer
Apr 24, 2003
60
US
I have a msflexgrid on a form which is bound to a recordset. How do I get the msflexgrid to refresh itself to reflect changes in a recordset? I tried msflexgrid.refresh and msflexgrid.redraw = true to no avail. Can anyone help?
 
You need to refresh the grids datasource (recordset or data control) and then refresh the grid.

Take Care,

zemp

"If the grass looks greener... it's probably because there is more manure."
 
I had already tried that and it didn't work. I refreshed the recordset and the grid. Does anyone have any other suggestions?
 
Post the code that you are using.

You might also have to reassign the datasource to the grid after it is refreshed and before the grid is refreshed.



Take Care,

zemp

"If the grass looks greener... it's probably because there is more manure."
 
I am using the msflexgrid control. I could not re-assign the datasource to the grid, received an error. I'm starting to wonder if there is a bug in the msflexgrid control that prohibits you from refreshing a msflexgrid based on changes in a recordset. In the code below I know there are definitely records in the recordset. I used messageboxes to read back field values--there is data there, it just won't re-populate into the msflexgrid. The data in the msflexgrid changes when a different ID is selected in another grid which is the rst8.fields("crime_victim_id") referenced in the select statement. The grid initially populates with data the first time but as soon as I refresh the recordset the data remained the same in the grid.

Here is my code, I have tried several different variations of it:

Set rst9 = nothing
Set rst9 = da_dbs.OpenRecordset("select * from Crime_Case where crime_victim_id =" & rst8.Fields("Crime_Victim_ID").Value)

MSFlexGrid2.Redraw = True

MSFlexGrid2.Clear

MSFlexGrid2.Rows = rst9.RecordCount
MSFlexGrid2.Cols = rst9.Fields.Count
MSFlexGrid2.Refresh
 
Do you have a data control as the datasource for the Flexgrid? If not you might want to add one and bind the recordset (rst9 or the SQL statement for it) to the data control and then bind the data control as the Flexgrid's datasource. In that format you only need two lines of code to refresh the flexgrid and you don't need the recordset object. Below is an example of what I have used.

Code:
Private Sub Form_Load()
   Data1.DatabaseName = App.Path & "\test.mdb"
   MSFlexGrid1.Refresh
End Sub

Private Sub Combo1_Click()
   Data1.RecordSource = "Select * From [tblCustomers] Where [Type]='" & Combo1.Text & "';"
   Data1.Refresh
End Sub

Most of the binding is taken care of in design mode.


Take Care,

zemp

"If the grass looks greener... it's probably because there is more manure."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top