DEV Community

Steema Software
Steema Software

Posted on

Adding TeeChart ActiveX to an MS Access Form

This guide explains how to add a TeeChart ActiveX control to an MS Access form and to populate it with data from a table.

Our sample data table looks like this:

Image description

We create a new form in the forms section of the Access space and set it to design. We then open the ActiveX Control selector from the form-design palette:

Image description

In this example there are many TeeChart controls to choose from. We’ll select the v2023 control and for this example we’ll also select the TeeCommander Bar.

Add the Chart and Commander to the Form and add and caption a button for the form. We’ll load the data from the Basic Table to the chart in the button. It’s not necessary to use the button, the data could be loaded in the form load, but here we’ll prompt it from the button.

Chart Editor

We right mouseclick on the Chart to open the Chart Editor to add a Series and to select a Chart Theme from the Themes selector.

Image description

Image description

Add code

Right mouseclick on the button on the form and select “Build event”. That takes us to the VBA code editor and creates a button-click method. Here we add the Chart fill code:

Image description

The code we’ve added for the button is this:

Private Sub Command2_Click()
  TChart1.Series(0).Clear
  strsql = "Select * From BasicTable"
  Set rs = CurrentDb.OpenRecordset(strsql)
  If Not (rs.EOF And rs.BOF) Then
    rs.MoveFirst 'Unnecessary in this case, but still a good habit
    Do Until rs.EOF = True
       'vars are xvalue,yvalue,label and colour. 
       'Auto colour is clTeeColor = 536870912 as referenced here:
       'https://github.com/Steema/TeeChart-ActiveX-   
       'Samples/blob/master/Visual%20C%2B%2B/TeeChartDefines.h
       TChart1.Series(0).AddXY rs!XValue, rs!YValue, "", 536870912
       rs.MoveNext
    Loop
  Else
    MsgBox "There are no records in the recordset."
  End If
  rs.Close
  Set rs = Nothing
End Sub
Enter fullscreen mode Exit fullscreen mode

You’ll notice we’ve also added a codeline in Form load to connect the TeeCommander bar to the Chart. ie:

Private Sub Form_Load(
 TeeCommander0.ChartLink = TChart1.ChartLink 
End Sub
Enter fullscreen mode Exit fullscreen mode

The resulting chart on the form looks like this:

Image description

Note the parameters for the AddXY method. We haven’t added labels and have let the Chart decide the colour according to the palette selected with the Theme. If we choose to add the record’s labels, modifying the codeline like this:

TChart1.Series(0).AddXY rs!XValue, rs!YValue, rs!Labels, 5368709
Enter fullscreen mode Exit fullscreen mode

Then the chart would appear like this:

Image description

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

Imagine monitoring that's actually built for developers

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay