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)