Change Chart's Row Source using VBA

S

Stelios

Hi,

I want to change a chart's Row Source using VBA. I want it because the
queries I want to use are dynamics and based each time on different tables.
Any Idea??
Thanks
 
V

Van T. Dinh

You can have a fixed Query name as the DataSource for the
Chart Object and you can modify the SQL String of the
Query to suit your data just before opening the Form that
contain the Chart Object.

For example, here is a small code extract from one of my
databases:

Set db = DBEngine(0)(0)
Set qdf = db.QueryDefs(GRAPH_QCUSTOM)
qdf.SQL = db.QueryDefs(GRAPH_QBASE).SQL & _
" WHERE (FL.frg_FactoryID = " & .cboFactoryID
& ") " & _
" AND (S.frg_ProductID = " & .cboProductID
& ") " & _
" AND (TB.SampleDateTime Between CONVERT
(datetime, '" & _
Format(.txtFromDate, "dd/mm/yyyy") & "',
103) And CONVERT(datetime, '" & _
Format(.txtToDate, "dd/mm/yyyy 23:59:59")
& "', 103) ) " & _
" AND (PSN.ProdSpecNameID = "
& .lstProdSpecName_SS & ")"
'Debug.Print qdf.SQL
qdf.Close

lngCount = DCount("*", GRAPH_QFINAL)
If lngCount = 0 Then
MsgBox "There is no Lab Result returned by the
criteria you selected." & vbCrLf & vbCrLf & _
"Please select different criteria.", vbOKOnly +
vbExclamation, "No Returned Data!"
GoTo cmdViewNow_Click_Exit
Else
DoCmd.OpenForm FORMNAME_GRAPH, , , , , acDialog, _
.lstProdSpecName_SS.Column(1) & " for "
& .cboProductID.Column(1)
End If

HTH
Van T. Dinh
MVP (Access)
 

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