CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Help Please

  1. #1
    Join Date
    Jul 1999
    Posts
    8

    Help Please

    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




  2. #2
    Guest

    Re: Help Please

    Maybe you need to pass the grid as a control. For example in your function
    use Private Sub fillgrid(rs as ADODB.Recordset, grid AS Control)



  3. #3
    Guest

    Re: Help Please

    Did you check for a valid connection? I noticed your connection string does not give a provider. Where is this data being read from?




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured