bind db to flexgrid ADO vs DAO

I am trying to bind an ADO recordset to my msflexgrid in vb6 using the following code:

Set conn = New ADODB.Connection
Set rec = New ADODB.Recordset

rec.CursorType = adOpenStatic
      rec.CursorLocation = adUseClient
      rec.LockType = adLockOptimistic
      rec.Open esql, conn, , , adCmdText


Dim i As Integer
Dim J As Integer


    MSFlexGrid1.FixedRows = 1
    MSFlexGrid1.FixedCols = 0
    
    If Not rec.EOF Then
    
        MSFlexGrid1.Rows = rec.RecordCount + 1
        MSFlexGrid1.Cols = rec.Fields.Count
        

    
        For i = 0 To rec.Fields.Count - 1
            MSFlexGrid1.TextMatrix(0, i) = rec.Fields(i).Name
           Next
    
        i = 1
        Do While Not rec.EOF
    
            For J = 0 To rec.Fields.Count - 1
                If Not IsNull(rec.Fields(J).Value) Then
                    MSFlexGrid1.TextMatrix(i, J) = _
                       rec.Fields(J).Value
                End If
            Next
    
        i = i + 1
        rec.MoveNext
        Loop
    
    
    End If
PopulateFlexGrid = True

Open in new window


Is there an easier way to do this using DAO?  If so, what would I change to accomplish that?
al4629740Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vastoCommented:
I don't have vb6 and FlexGrid available now, but as far as I remember you can use DataSource to set the data.

Set conn = New ADODB.Connection
Set rec = New ADODB.Recordset

rec.CursorType = adOpenStatic
      rec.CursorLocation = adUseClient
      rec.LockType = adLockOptimistic
      rec.Open esql, conn, , , adCmdText

Set MSFlexGrid1.DataSource = rec

Dao will not make the things different, it is just a different way to connect to the database
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
al4629740Author Commented:
Error:

Object variable or With block variable not set

This line

Set MSFlexGrid1.DataSource = rec
0
vastoCommented:
Can you debug the application and check which one is nothing : MSFlexGrid1 or rec ?
0
al4629740Author Commented:
MSFlexGrid1
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.