bartman123
asked on
Modifying MS Graph data using VBA
Hi all,
Just wondering if there is a way to modify or change the RowSource property of the MS Graph object?
I have a report with a graph embedded in it but I can find a way to change the SQL query behind the graph. Anything I try doesn't work (i.e. like trying to set GraphObject.Application.Da taSheet properties). I get errors like "object doesn't support that property or method" or others to that effect.
I can set the underlying query using a macro by changing the value of [Reports]![MainReport]![Gr aphObject] .[RowSourc e] using SetValue, but how on earth do I do this using VBA? I would have thought that this would have been a handy feature to have so why isn't it easy to find (or maybe I'm just going blind)
any help in this matter would be great.
Bart.
Just wondering if there is a way to modify or change the RowSource property of the MS Graph object?
I have a report with a graph embedded in it but I can find a way to change the SQL query behind the graph. Anything I try doesn't work (i.e. like trying to set GraphObject.Application.Da
I can set the underlying query using a macro by changing the value of [Reports]![MainReport]![Gr
any help in this matter would be great.
Bart.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you want you could save the report so the graph is based on a query then use code to modify the query, this will be required if yiou decide to use an MDE file.
You will need to check you have a reference to Microsoft DAO to do this go to your module and from the VBA window go to the Tools Menu, References and ensure the latest version of Microsoft DAO is selected.
then change your OnClick event to
dim db as database
dim qd as querydef
set db = currentdb()
set qd = db.QueryDefs("MyGraphQuery ")
qd.sql = "SELECT First(results_local.Future _Intention s) AS [Future_Intentions Field], Count _
(results_local.Future_Inte ntions) AS NumberOfDups FROM results_local _
GROUP BY results_local.Future_Inten tions HAVING _
(((Count (results_local.Future_Inte ntions))>1 ));"
qd.close
DoCmd.OpenReport "MainReport", acViewPreview, "", ""
Cheers, Andrew
You will need to check you have a reference to Microsoft DAO to do this go to your module and from the VBA window go to the Tools Menu, References and ensure the latest version of Microsoft DAO is selected.
then change your OnClick event to
dim db as database
dim qd as querydef
set db = currentdb()
set qd = db.QueryDefs("MyGraphQuery
qd.sql = "SELECT First(results_local.Future
(results_local.Future_Inte
GROUP BY results_local.Future_Inten
(((Count (results_local.Future_Inte
qd.close
DoCmd.OpenReport "MainReport", acViewPreview, "", ""
Cheers, Andrew
ASKER
Thanks TextReport for your answers....the first one did the trick and is what I need to get the job done....It has opened up another problem but I'll leave that for another topic....(unless you know how to display more than one set of results per graph....tell me what is wrong with the following statement?)
SQL_WorkingConditions = "SELECT results_local.OHnS, Count(results_local.Amenit ies) _
AS Amenities, Count(results_local.OHnS) AS [OHnS Practices] _
FROM results_local GROUP BY results_local.OHnS _
HAVING (((Count(results_local.Ame nities))>0 ) AND ((Count(results_local.OHnS ))>0));"
Both Amenities and OHnS contain one of 5 values. The resulting graph shows two columns per item but they both show the same thing.
Bart
SQL_WorkingConditions = "SELECT results_local.OHnS, Count(results_local.Amenit
AS Amenities, Count(results_local.OHnS) AS [OHnS Practices] _
FROM results_local GROUP BY results_local.OHnS _
HAVING (((Count(results_local.Ame
Both Amenities and OHnS contain one of 5 values. The resulting graph shows two columns per item but they both show the same thing.
Bart
You probably need to group by the first field in your select but as you say that's another issue, cheers, Andrew
ASKER
I've converted the macro to a module as you suggested so I'll give that a burl and see what happens...
For those who are interested the converted macro looks something like this
DoCmd.Echo False, ""
DoCmd.OpenReport "MainReport", acViewDesign, "", ""
Reports!MainReport!GraphOb
(results_local.Future_Inte
(results_local.Future_Inte
GROUP BY results_local.Future_Inten
(((Count (results_local.Future_Inte
DoCmd.RunCommand acCmdSave
DoCmd.OpenReport "MainReport", acViewPreview, "", ""
DoCmd.Echo True, ""