Filling a Grid with Data from a Database

See AlsovbhowFillGridWithDataSee                 ExamplevbhowFillGridWithDataEx>Low

It may be convenient for your users to use a grid control to view data from your database.  You can quickly put data from a DynasetUDR386 or Snapshot1ZLURBC into a grid.

To clear data from a grid

  1. Select all cells on the grid:

      Grid1.SelStartCol = 0
Grid1.SelEndCol = Grid1.Cols - 1
Grid1.SelStartRow = 0
Grid1.SelEndRow = Grid1.Rows - 1


  2. Clear the selected cells:

      Grid1.Clip = ""


To place data into a grid

  1. Determine how many rows and columns are in the recordset (the code in the example assumes one fixed column and one fixed row), then set the size of the grid.

Grid1.Rows = Data1.Recordset.RecordCount + 1
Grid1.Cols = Data1.Recordset.Fields.Count + 1


  2. Move through the recordset until you reach the last record, using a Do Until...EOF loop:

      Do Until Data1.Recordset.EOF


  3. For each record, put values into each column of the current row of the grid.  Values that are Null or too large will produce an error.  You can avoid such errors by using an On Error Resume Next statement.