Results 1 to 3 of 3

Thread: binding(?) MSChart to recordset

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2007
    Posts
    234

    binding(?) MSChart to recordset

    here is "my" code i coped from examples
    Code:
    Option Explicit
    Private rs As ADODB.Recordset
    Private objSource As MySource
    Private objBindingCollection As BindingCollection
    
    Private Sub Class_GetDataMember(DataMember As String, Data As Object)
       Set Data = rs
    End Sub
    
    Private Sub Class_Initialize()
        Dim thick As Single, trans As Single
        Dim i As Integer
        Dim FP As Variant
        ReDim FP(1 To 2)
        Set rs = New ADODB.Recordset
        With rs
            .Fields.Append "Thickness", adSingle
            .Fields.Append "Transmission", adSingle
            .CursorType = adOpenStatic
            .LockType = adLockOptimistic
            .Open
        End With
       For i = 1 To 100
                With rs
                   .AddNew
                   .Fields.Item("Thickness") = i
                   FP(1) = 1.68
                   FP(2) = i
                   .Fields.Item("Transmission") = Rpc(5000, 1.52, 1, FP)
                   .Update
                End With
       Next i
       rs.MoveFirst
    End Sub
    this makes MySource.cls that i copied from http://msdn2.microsoft.com/en-us/lib...35(VS.60).aspx

    how do I get this rs to be displayed in an MSChart like this: MSChart.DataSource = rs
    ???

    i know nothing...all i'm asking for is a tip or a pointer that will let me bind this stuff together to work. thanks for any help

    i'm guessing there is a difference between a Recordset and a Connection...but how to use one inplace of another i have no clue...
    Last edited by unxzst; Mar 26th, 2008 at 03:31 PM.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: binding(?) MSChart to recordset

    all i'm asking for is a tip or a pointer that will let me bind this stuff together to work.
    Personally, I would stay away from writing Data Aware classes and Data Binding altogether. Most controls let you bind directly to an ADO recordset anyway, so in my opinion Data Aware classes are overkill and not worth the effort. Even Data Binding controls directly to a Recordset is considered "bad practice" but I see nothing wrong with binding read only data for display purposes.

    So I would bind the Chart directly to the recordset by moving the code within the Class_Initialize event, to the Form_Load event of the Form that contains the MSChart control. The statement to bind is simply

    Set MSChart.DataSource = rs

    In their most basic form, an ADO Connection object allows you to "connect" to a data store. In most cases data store means some sort of database, like MS Access, SQL Server or Oracle but it can be a Text file, Excel spreadsheet. The Connection object executes queries against the data store and the ADO Recordset object contains the results of those queries.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2007
    Posts
    234

    Re: binding(?) MSChart to recordset

    cool, thanks. I kinda knew this was a back-asswords way, but i didnt realize its that simple
    this is what i've got
    Code:
    Private rs As ADODB.Recordset
    Private Sub Form_Load()
        Dim thick As Single, trans As Single
        Dim i As Integer
        Dim FP As Variant
        ReDim FP(1 To 2)
        Set rs = New ADODB.Recordset
        With rs
            .Fields.Append "Thickness", adSingle
            .Fields.Append "Transmission", adSingle
            .CursorType = adOpenStatic
            .LockType = adLockOptimistic
            .Open
        End With
        For i = 1 To 100
            FP(1) = 1.68
            FP(2) = i
            With rs
                .AddNew
                .Fields.Item("Thickness") = i
                .Fields.Item("Transmission") = Rpc(5000, 1.52, 1, FP)
                .Update
            End With
        Next i
    '    rs.MoveFirst 'not sure why this is here...yet
        With MSChart1
            Set .DataSource = rs
            .chartType = VtChChartType2dLine
        End With
    end sub
    thanks for your help, seems to be working now, just have to format the chart

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