Using DateTime X-Axis Labels on MSChart control

J

jtertin

I am using the below subroutine to load data for a MSChart control in
Access. The query "ChartData" is dynamically linked to a SQL linked
table. I wanted to take this approach so the chart would dynamically
adjust itself to the table regardless of the number of columns in the
recordset.

My problem is that the first column in my record set (columns below)
is a DateTime data type. I found that I could not use this timestamp
as labels for my X-Axis unless I cast it as a VARCHAR before using
it. However, if I do this, the X-Axis is no longer automatically
scaled, so when I get >50 points on my graph, they all run together.

Is there a way to make this work? Can an MSChart use (and
automatically scale) the DateTime data type as an X-Axis unit?

=============================================

Private Sub Form_Load()
Dim con As Object
Dim ChartRecordset As Object
Set con = Application.CurrentProject.Connection
Set ChartRecordset = CreateObject("ADODB.Recordset")

ChartRecordset.Open "SELECT * from [ChartData]", con, adOpenStatic,
adLockOptimistic

With Chart
Set .DataSource = ChartRecordset
.ShowLegend = True
End With
End Sub

=============================================

Record Set (Dyamic number of columns):
[dtDateTime],[Column1],[Column2],[Column3],[Column4]

I would like to use dtDateTime (in database as DateTime type) as
labels for my X-Axis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top