Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

bind db to flexgrid  ADO vs DAO

Posted on 2014-09-02
4
Medium Priority
?
270 Views
Last Modified: 2014-09-20
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?
0
Comment
Question by:al4629740
  • 2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
vasto earned 1000 total points
ID: 40301140
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
 

Author Comment

by:al4629740
ID: 40302343
Error:

Object variable or With block variable not set

This line

Set MSFlexGrid1.DataSource = rec
0
 
LVL 18

Expert Comment

by:vasto
ID: 40302433
Can you debug the application and check which one is nothing : MSFlexGrid1 or rec ?
0
 

Author Comment

by:al4629740
ID: 40302726
MSFlexGrid1
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question