Results 1 to 6 of 6

Thread: DBGrid problems

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Finland
    Posts
    13

    Unhappy

    Hi!

    I'm having problems displaying my database.

    First I set up my DB with

    Set objSource = New clsEyeDB

    Then, when I try to set the datasource for my DBGrid with

    Set dbData.DataSource = objSource

    I end up with an error:
    "Run-time error 403:
    Class does not support automation or does
    not support expected interface"

    Also, how do I select which items to display from the
    recordset at runtime depending on the users actions, say
    "Show all events of type 2 and 4"?

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    1st Question: Are you using ADO recordsets? the DBGrid only supports DAO recordsets

    2nd Question: Use a filter on your recordset or requery the database for the specified criteria

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Finland
    Posts
    13
    Ah, well in that case, how do I fill up a flexgrid with database data. I can get the flexgrid to display the field names with

    Set objSource = New MyDBClass

    Set FlexGrid.DataSource = objSource

    (And MyDBClass is pretty straightforward and works ok) But I can't seem to find a way to fill the grid. All the bound textfields on my form fill up nicely, apparently the Datasource property doesn't work as easily (at least not for me).

    Thanks for the feedback,

    K

  4. #4
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    is objSource an ADO RS or something? what are your custom objects?

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Finland
    Posts
    13
    OK, here we go..

    objSource is an ADODB Recordset.

    --- snippet ---

    'Class clsEyeDB

    Option Explicit
    Private rs As ADODB.Recordset

    Private Sub Class_GetDataMember(DataMember As String, data As Object)
    'Assign the Recordset to the Data Object
    Set data = rs
    End Sub

    Private Sub Class_Initialize()

    'Create an instance of the recordset
    Set rs = New ADODB.Recordset

    'Set the properties of the recordset
    With rs
    'fields
    .Fields.Append "EventID", adInteger

    ' and so forth..

    'other stuff
    .CursorType = adOpenStatic
    .LockType = adLockOptimistic
    .Open
    End With

    End Sub

    --- snippety snip ---

    In my program I fill this RS up with data read from an
    ASCII file, and this seems to be working fine.

    Now I'm (desperately) trying to display the
    (filtered/unfiltered) contents of the recordset in a
    tabular form, preferrably a flexgrid.

    ---8<----

    Private objSource As clsEyeDB

    Private Sub Form_Load()

    Set fgData.DataSource = objSource 'fgData is a flexGrid

    End Sub

    ---8<----

    Now how do I get the flexGrid to fill up/update with my RS?
    Do I have to fill it up row by row or is there a way to
    automate this and to have the flexGrid update whenever the
    RS changes?

    And by custom objects you mean what exactly..?

  6. #6
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    ah, your objSource is a data provider

    sorry for my ignorance, I haven't played with making a data provider as of yet....

    this will put your data into a flexgrid -- you'll want to add column headings and stuff, but this will get you started

    Code:
        Dim cn As New Connection
        Dim rs As New Recordset
        Dim strRS As String
        Dim strRows() As String
        Dim i As Long
        
        
        cn.Open "Provider=Microsoft.jet.OLEDB.4.0;Data Source=Nwind.mdb"
        
        'get rs
        rs.Open "Select * from Customers", cn, adOpenStatic, adLockReadOnly, adCmdText
        
        'set number of cols
        MSFlexGrid1.Cols = rs.Fields.Count
        
        'get formatted string of data -- use the vbTab because
        'that is how the msflexgrid likes it as a parameter
        strRS = rs.GetString(, , vbTab, "|", "")
        
        'separate by rows into array
        strRows = Split(strRS, "|")
        
        'loop thru array
        For i = LBound(strRows) To UBound(strRows)
            'add row to grid
            MSFlexGrid1.AddItem strRows(i)
            DoEvents
        Next i
        
        'cleanup....

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