Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Modifying MS Graph data using VBA

Posted on 2003-11-30
5
Medium Priority
?
1,500 Views
Last Modified: 2009-07-29
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.DataSheet 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]![GraphObject].[RowSource] 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.
0
Comment
Question by:bartman123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 28

Accepted Solution

by:
TextReport earned 240 total points
ID: 9849021
If the graph is on a form then there are no problems but in a report you cannot change the rowsource property once the report is opened. Therefore you have to modify the SQL of the Query if you can.

Where are you running the Macro from?
If you go into the design of the macro and do a save as you can save it as a moule and you will see it there.

If you are running this from the Report open event then you can say

Me!GraphObject.RowSource = "MyNewQuery"

Cheers, Andrew
0
 
LVL 1

Author Comment

by:bartman123
ID: 9853862
The macro is run as an onclick event for a form button. I actually pinched it from a microsoft access example that was converted from 97 to 2000 (I forget the article number but the file is Grphsm97.exe). It works well but I'd rather have the VBA code do it.

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!GraphObject.RowSource = "SELECT First _
    (results_local.Future_Intentions) AS [Future_Intentions Field], Count _
    (results_local.Future_Intentions) AS NumberOfDups FROM results_local _
    GROUP BY results_local.Future_Intentions HAVING _
    (((Count (results_local.Future_Intentions))>1));"
DoCmd.RunCommand acCmdSave
DoCmd.OpenReport "MainReport", acViewPreview, "", ""
DoCmd.Echo True, ""
0
 
LVL 28

Expert Comment

by:TextReport
ID: 9854151
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_Intentions) AS [Future_Intentions Field], Count _
    (results_local.Future_Intentions) AS NumberOfDups FROM results_local _
    GROUP BY results_local.Future_Intentions HAVING _
    (((Count (results_local.Future_Intentions))>1));"
qd.close

DoCmd.OpenReport "MainReport", acViewPreview, "", ""

Cheers, Andrew
0
 
LVL 1

Author Comment

by:bartman123
ID: 9854829
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.Amenities) _
  AS Amenities, Count(results_local.OHnS) AS [OHnS Practices] _
  FROM results_local GROUP BY results_local.OHnS _
  HAVING (((Count(results_local.Amenities))>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
0
 
LVL 28

Expert Comment

by:TextReport
ID: 9856120
You probably need to group by the first field in your select but as you say that's another issue, cheers, Andrew
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question