By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,610 Members | 1,330 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,610 IT Pros & Developers. It's quick & easy.

graph connect with micrsoft access

P: 18
Hye...
I want to draw a graph which connected to data in microsoft access. How to do it, and what component should i include.
thnx..
Mar 15 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 5K+
P: 8,434
Hye...
I want to draw a graph which connected to data in microsoft access. How to do it, and what component should i include.
That sounds like a job for the Microsoft Chart Control (which is what to look for in the component list).
Mar 15 '07 #2

P: 18
Thnx for the reply... and here i want to share the codes with others.... simple graph...i like it

component needed... mschart
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. ' Be sure to set a reference to the Microsoft ActiveX Data
  3. ' Objects 2.0 Library.
  4. Private rsProducts As New ADODB.Recordset
  5. Private cn As New ADODB.Connection
  6.  
  7. Private Sub Form_Load()
  8.    Dim strQuery As String ' SQL query string.
  9.    Dim a As Integer
  10.    Dim b As String
  11.  
  12.    ' First change the path to a valid path for your machine.
  13.    cn.ConnectionString = _
  14.    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=your database location;Persist Security Info=False"
  15.  
  16.    ' Open the connection.
  17.    cn.Open
  18.  
  19.    ' Create a query that retrieves only four fields.
  20.    strQuery = "SELECT Date, Sum from Query1"
  21.    ' Open the recordset.
  22.    rsProducts.Open strQuery, cn, adOpenKeyset
  23.    ' Set the DataSource to the recordset.
  24.    With MSChart1
  25.      .ShowLegend = True
  26.      Set .DataSource = rsProducts
  27.  
  28.      Dim X() As Variant
  29.  
  30.    End With
  31.  
  32.    If a > 0 Then
  33.         ReDim X(1 To a, 1 To 2)
  34.         Dim i As Integer
  35.         i = 1
  36.         While Not rsProducts.EOF
  37.             X(i, 1) = rsProducts("Date") 'Date field in Query1 
  38.             X(i, 2) = rsProducts("Sum") 'Sum field in Query1
  39.             i = i + 1
  40.             rsProducts.MoveNext
  41.         Wend
  42.         MSChart1.ChartData = X
  43.     End If
  44.  
  45. End Sub
Mar 17 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.