hima
July 27th, 1999, 10:26 AM
Hello,
i am trying to open a recordset and display the records in
Msflexgrid control. Following is my sample code.
Dim cnn As ADODB.connection
Dim cmd As ADODB.Command
Dim strcnn As String
Set cnn = New connection
strcnn = "data source = sample;uid=;pwd=;"
cnn.Open strcnn
Dim rs As ADODB.Recordset
Set rs = New Recordset
rs.ActiveConnection = cnn
rs.Open "select * from authors", , , , adCmdText
fillgrid rs, grid 'fillgrid is a function
End Sub
***Function is
Private Sub fillgrid(rs As ADODB.Recordset, grid As MSFlexGrid)
Dim fld As ADODB.Field
grid.Redraw = False
grid.Cols = rs.Fields.Count
grid.Rows = 1
grid.Row = 0
grid.Col = 0
For Each fld In rs.Fields
grid.ColWidth(grid.Col) = TextWidth(String(fld.ActualSize + 4, "a"))
grid.ColAlignment(grid.Col) = 1
grid.Text = fld.Name
If grid.Col < rs.Fields.Count - 1 Then
grid.Col = grid.Col + 1
End If
Next fld
Do Until rs.EOF
grid.Rows = grid.Rows + 1
grid.Row = grid.Rows - 1
grid.Col = 1
For Each fld In rs.Fields
grid.Text = fld.Value
If grid.Col < rs.Fields.Count - 1 Then
grid.Col = grid.Col + 1
End If
Next fld
rs.MoveNext
Loop
End Sub
Problem is when i am calling the function i got an error 'Object variable
or with block variable not set'. i checked the value of the grid. it is
returning nothing.
Any help appreciated!
Hima
i am trying to open a recordset and display the records in
Msflexgrid control. Following is my sample code.
Dim cnn As ADODB.connection
Dim cmd As ADODB.Command
Dim strcnn As String
Set cnn = New connection
strcnn = "data source = sample;uid=;pwd=;"
cnn.Open strcnn
Dim rs As ADODB.Recordset
Set rs = New Recordset
rs.ActiveConnection = cnn
rs.Open "select * from authors", , , , adCmdText
fillgrid rs, grid 'fillgrid is a function
End Sub
***Function is
Private Sub fillgrid(rs As ADODB.Recordset, grid As MSFlexGrid)
Dim fld As ADODB.Field
grid.Redraw = False
grid.Cols = rs.Fields.Count
grid.Rows = 1
grid.Row = 0
grid.Col = 0
For Each fld In rs.Fields
grid.ColWidth(grid.Col) = TextWidth(String(fld.ActualSize + 4, "a"))
grid.ColAlignment(grid.Col) = 1
grid.Text = fld.Name
If grid.Col < rs.Fields.Count - 1 Then
grid.Col = grid.Col + 1
End If
Next fld
Do Until rs.EOF
grid.Rows = grid.Rows + 1
grid.Row = grid.Rows - 1
grid.Col = 1
For Each fld In rs.Fields
grid.Text = fld.Value
If grid.Col < rs.Fields.Count - 1 Then
grid.Col = grid.Col + 1
End If
Next fld
rs.MoveNext
Loop
End Sub
Problem is when i am calling the function i got an error 'Object variable
or with block variable not set'. i checked the value of the grid. it is
returning nothing.
Any help appreciated!
Hima