473,799 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

1004 Unable to set the Values property of the Series class

48 New Member
Hello,

I've been coding in Access VBA to create an Excel Graph and it was good.

Until I got this error:
1004 Unable to set the Values property of the Series class
Please check the code below:
Expand|Select|Wrap|Line Numbers
  1. Private Sub TestGraph3()
  2.  
  3.     Dim oXL As Excel.Application    ' Excel application
  4.     Dim oBook As Excel.Workbook     ' Excel workbook
  5.     Dim oSheet As Excel.Worksheet   ' Excel Worksheet
  6.     Dim oChart As Excel.Chart       ' Excel Chart
  7.  
  8.     Dim myRange As String
  9.     Dim xlSourceRange As Excel.Range
  10.  
  11.     Dim iRow As Integer      ' Index variable for the current Row
  12.     Dim iCol As Integer      ' Index variable for the current Row
  13.  
  14.     Const cNumCols = 4       ' Number of points in each Series
  15.     Const cNumRows = 5       ' Number of Series
  16.  
  17.     ReDim aTemp(1 To (cNumRows + 1), 1 To cNumCols)
  18.  
  19.     ' Start Excel and create a new workbook
  20.     Set oXL = CreateObject("Excel.application")
  21.     Set oBook = oXL.Workbooks.Add
  22.  
  23.     Set oSheet = oBook.Worksheets.Item(1)
  24.  
  25.     ' Insert data into Cells for the two Series:
  26.     For iCol = 1 To cNumCols
  27.        aTemp(1, iCol) = "A" & iCol
  28.        aTemp(2, iCol) = 1
  29.        aTemp(3, iCol) = 1 + 2
  30.        aTemp(4, iCol) = iCol
  31.  
  32.        If (iCol * 2) <= cNumCols Then
  33.         aTemp(5, iCol) = iCol * 2
  34.        Else
  35.         aTemp(5, iCol) = cNumCols
  36.        End If
  37.     Next iCol
  38.  
  39.     oSheet.Range("A1").Resize(5, cNumCols).Value = aTemp
  40.  
  41.     oSheet.Name = "MyChart_MD"
  42.  
  43.     myRange = "A1:D" & (cNumRows)
  44.     Set xlSourceRange = oBook.Worksheets(1).Range(myRange)
  45.  
  46.     Set oChart = oXL.Charts.Add
  47.  
  48.     With oChart
  49.         .SetSourceData Source:=xlSourceRange, PlotBy:=xlColumns
  50.         .ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Line - Column"
  51.  
  52.         .SeriesCollection(1).XValues = oSheet.Range("A1").Resize(1, cNumCols)
  53.         .SeriesCollection(1).Values = oSheet.Range("A2").Resize(1, cNumCols)
  54.         .SeriesCollection(1).Name = "Plan"
  55.         .SeriesCollection(2).Values = oSheet.Range("A3").Resize(1, cNumCols)
  56.         .SeriesCollection(2).Name = "Actual"
  57.         .SeriesCollection(3).Values = oSheet.Range("A4").Resize(1, cNumCols)
  58.         .SeriesCollection(3).Name = "Accu. Plan"
  59.         .SeriesCollection(4).Values = oSheet.Range("A5").Resize(1, cNumCols)
  60.         .SeriesCollection(4).Name = "Accu. Actual"
  61.         .Location Where:=xlLocationAsNewSheet, Name:="chartMD"
  62.  
  63.         .HasTitle = True
  64.         .ChartTitle.Characters.Text = "Chart : MD"
  65.         .Axes(xlCategory, xlPrimary).HasTitle = False
  66.         .Axes(xlValue, xlPrimary).HasTitle = True
  67.         .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Accu."
  68.         .Axes(xlCategory, xlSecondary).HasTitle = False
  69.         .Axes(xlValue, xlSecondary).HasTitle = False
  70.  
  71.         .HasLegend = False
  72.         .HasDataTable = True
  73.         .DataTable.ShowLegendKey = True
  74.     End With
  75.  
  76.     ' Make Excel Visible:
  77.     oXL.Visible = True
  78.     oXL.UserControl = True
  79.     ' Unselect the ActiveChart
  80.     oChart.Deselect
  81.     oXL.ActiveWindow.Zoom = 85
  82.  
  83.     ' Protect whole Worksheet
  84.     oSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
  85.  
  86.     ' Clean-up
  87.     Set oXL = Nothing: Set oChart = Nothing: Set oSheet = Nothing: Set oBook = Nothing
  88.  
  89. End Sub
  90.  
If cNumCols = 3, ERROR occurs in this line:
Expand|Select|Wrap|Line Numbers
  1.         .SeriesCollection(4).Values = oSheet.Range("A5").Resize(1, cNumCols)
  2.  
If cNumCols = 2, ERROR occurs in this line:
Expand|Select|Wrap|Line Numbers
  1.         .SeriesCollection(3).Values = oSheet.Range("A5").Resize(1, cNumCols)
  2.  

cNumCols is supposed to be the number of points in each series.
Not the number of series.
cNumRows is the number of series.

In a situation where there are 4 Series (Actual, Plan, Accu. Actual, Accu. Plan)
how can I display a graph/chart with 3 columns only?

Help will be greatly appreciated.
Sep 11 '08 #1
4 5922
NeoPa
32,579 Recognized Expert Moderator MVP
I can't help with this I'm afraid, but I have a couple of suggestions as to how you can make your question more attractive to potential responders.
  1. When you have a large amount of code to post, please do the legwork first to remove anything which is not relevant to the problem. Produce the smallest set of code that you can which still exhibits the problems you're suffering from.
    Simply dumping your native code in for someone else to go through won't win you many friends.
  2. The [ CODE ] tags you've used add line numbers when they display. When referring to lines in your code it is most easy to do this by the line number.
I would just add that, while point number one is about courtesy, it also has the added benefit of giving you a better understanding of your own code as you process through deciding what to strip. In fact it's fairly common during this process to discover for yourself the problem you're posting to find.

Good luck anyway with your question.
Sep 11 '08 #2
keirnus
48 New Member
I can't help with this I'm afraid, but I have a couple of suggestions as to how you can make your question more attractive to potential responders.
  1. When you have a large amount of code to post, please do the legwork first to remove anything which is not relevant to the problem. Produce the smallest set of code that you can which still exhibits the problems you're suffering from.
    Simply dumping your native code in for someone else to go through won't win you many friends.
  2. The [ CODE ] tags you've used add line numbers when they display. When referring to lines in your code it is most easy to do this by the line number.
I would just add that, while point number one is about courtesy, it also has the added benefit of giving you a better understanding of your own code as you process through deciding what to strip. In fact it's fairly common during this process to discover for yourself the problem you're posting to find.

Good luck anyway with your question.
Thank you NeoPa for the advice.

I posted them all so others could easily test.
I understand it is not their job to test but to give advice.
I will keep that in mind.


...and I'm still stuck in this weirdness of this Chart's Series Class.
Sep 12 '08 #3
keirnus
48 New Member
Finally solved the intermittent problem!

Acknowledgment goes to Mr. Jon Peltier.
He's very helpful and yet an expert in this field.


Line and XY charts don't like it when a series starts with no data.
He's advice is to set Chart Type to xlColumnCluster ed which will
set blank data into valid ones. Then, re-insert the original line
after setting all the data.

Let's base from the above code.

The following lines must be changed from this:

Expand|Select|Wrap|Line Numbers
  1.         ....
  2.         .SetSourceData Source:=xlSourceRange, PlotBy:=xlColumns
  3.         .ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Line - Column"
  4.         ....
  5.  
...into this:
Expand|Select|Wrap|Line Numbers
  1.         ....
  2.         .ChartType = xlColumnClustered
  3.         .SetSourceData Source:=xlSourceRange
  4.         ....
  5.  
Not only the Chart Type and the sequence of the lines have changed
but the SetSourceData as well.

Note:
Not changing the sequence of lines seems not to fix the problem.
It only takes longer time before the error occurs again.
Don't have explanation on this yet.

Now, after modifying as stated above, let's re-insert the original line:
Expand|Select|Wrap|Line Numbers
  1.         ....
  2.         .SeriesCollection(4).Name = "Accu. Actual"
  3.         .ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Line - Column" ' <-- this one!
  4.         .Location Where:=xlLocationAsNewSheet, Name:="chartMD"
  5.         ....
  6.  
Eureka!

Intermittent problem gone.

Hope this helps you the way it helped much to me!


keirnus
Sep 12 '08 #4
NeoPa
32,579 Recognized Expert Moderator MVP
Thank you for the answer Keirnus. That's much appreciated.

My earler point, about stripping down the code, was about setting up a test rig rather than simply cutting out what you post from your code. To be honest, although we'd appreciate that method, we very rarely come across it, so don't worry too much (although I would still maintain it often proves a very real benefit to the poster).

Anyway, your posted solution (so clearly explained too) should prove very helpful, so full marks for that :)
Sep 12 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2300
by: Arun Nair | last post by:
Hi, I have the following jsp page. I am able to view only a part of it(until the occurence of the first City text box). If i remove the first few fields from the page, I am able to see a few more fields at the bottom. My form class contains all the properties that are used in the jsp page. I don't know what I am doing wrong. I am using struts1.1 & JDK 1.4.2.
3
3163
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and populate a combo box with these names. (this way, I can display all the EMPLOYEE_NAME values) (2) In general, can I do additional processing on column values from
5
2069
by: Edward Diener | last post by:
I am gathering from the documentation that return values from __events are not illegal but are frowned upon in .NET. If this is the case, does one pass back values from an event handler via "in/out" or "out" parameters ? Or is it simply that events are just notifications and are not interested in any values which event handlers might be able to return ? If the latter is the case, the event model in .NET appears to have a great...
4
2562
by: Chris Bower | last post by:
Reposted from aspnet.buildingcontrols: Ok, I've got a bunch of derived controls that all have a property Rights of type Rights (Rights is an Enumerator). I wrote a custom TypeConverter so that I can use comma separated values in design-time. The TypeConverter works great in design-time. It converts to and from just fine... However, when I try to load any page in the site now I get the following error (Following the error is code for the...
1
2956
by: epatrick | last post by:
I have a series of custom controls developed under ASP.NET 1.1, and I've successfully migrated to ASP.NET 2.0. I have also developed a custom class dervied from System.Web.UI.Page, called qbo.Web.Page. All of these controls compile and run correctly under ASP.NET 2.0. However, several of these controls throw an error in the design mode of VS.NET 2005. Specifically, controls that include a property override of Page (to cast as a...
3
6307
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am sending my code here.. Thanks in Advance... Regards
0
2952
by: forgedascendant | last post by:
Good day everyone, I am new to this site so please forgive me if this post isn't completly correct. For the past 2 weeks I have been beating my head against the wall trying to figure out what is wrong with the macro I created. The problem I am experiancing is that the range I am trying to put together does not seem to be working for some reason. My entire code is as follows: Sub Proto1() ' ' Proto1 Macro ' Macro recorded 8/30/2007...
14
3608
by: =?Utf-8?B?Umljaw==?= | last post by:
I have seen examples of passing data from FormB to FormA (Parent To Child) but I need an example of passind data from FormA to FormB. My main form is FormA; I will enter some data in textboxes and click a button to bring up FormB which needs to display values entered in FormA. Thanks in advance.
2
2363
by: Andy B | last post by:
I have the following listView control on a page: <asp:ListView ID="ListView1" runat="server" ItemPlaceholderID="PlaceHolder1"> <ItemTemplate> <dl> <dt>
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.