473,757 Members | 10,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help Creating a Excel graph in Access with VBA

I am using Access to create an Excel spreadsheets with graphs related
to rows on the sheet1 to the graph on sheet2. I am using the same data
but different subsets of the data to make different spreadsheets for
different groups. The spreadsheet formats are the same for each of the
different groups. So I am using a loop to requery the data for the
different groups and create a new spreadsheet for each group. The
three graphs on sheet 2 will work the first time through the loop but
when it creates a new spreadsheet for the next group I get these
errors.
"1004 Application-defined or object-defined error"
"1004 Unable to set the Position property of the Legend class"
"1004 "Method 'Worksheets' of object '_Global' failed"

I have to close Access for the graph to work the first time.

Dim myChtObj As Excel.ChartObje ct
Set objSheet = objXL.Worksheet s("Sheet2")
objSheet.Activa te
j = 0
For i = 1 To 3
Set myChtObj = objSheet.ChartO bjects.Add (Left:=10, Width:=750,
Top:=10 + j, Height:=400)
objSheet.ChartO bjects(i).Activ ate
With objXL.ActiveCha rt
.ChartType = xlXYScatterLine s
.SeriesCollecti on.Add
Source:=Workshe ets("Sheet1").R ange("A18:AN20" )
.Legend.Positio n = xlLegendPositio nBottom
End With
j = j + 410
Next i

I would appreciate any help.

Mitch

Oct 15 '06 #1
1 4617
I found my problem. After the first spreadsheet is closed there is
still and instance of Excel running and then when the second
spreadsheet opens it starts another instance of Excel. I was wonder if
anyone has a way of using the instance of Excel that is created when it
opens the spreadsheet to write to. I am going to have to inform the
end user that all instances of Excel have to be closed before he starts
to make the reports in the spreadsheets.
Mitch wrote:
I am using Access to create an Excel spreadsheets with graphs related
to rows on the sheet1 to the graph on sheet2. I am using the same data
but different subsets of the data to make different spreadsheets for
different groups. The spreadsheet formats are the same for each of the
different groups. So I am using a loop to requery the data for the
different groups and create a new spreadsheet for each group. The
three graphs on sheet 2 will work the first time through the loop but
when it creates a new spreadsheet for the next group I get these
errors.
"1004 Application-defined or object-defined error"
"1004 Unable to set the Position property of the Legend class"
"1004 "Method 'Worksheets' of object '_Global' failed"

I have to close Access for the graph to work the first time.

Dim myChtObj As Excel.ChartObje ct
Set objSheet = objXL.Worksheet s("Sheet2")
objSheet.Activa te
j = 0
For i = 1 To 3
Set myChtObj = objSheet.ChartO bjects.Add (Left:=10, Width:=750,
Top:=10 + j, Height:=400)
objSheet.ChartO bjects(i).Activ ate
With objXL.ActiveCha rt
.ChartType = xlXYScatterLine s
.SeriesCollecti on.Add
Source:=Workshe ets("Sheet1").R ange("A18:AN20" )
.Legend.Positio n = xlLegendPositio nBottom
End With
j = j + 410
Next i

I would appreciate any help.

Mitch
Oct 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2532
by: Jeff Blee | last post by:
I am hoping someone can help me. I am making a Access 97 app for a person and have run up against a problem to do with MS Graph. There is a table that has a number of data elements and a date field and entries are entered each month. A graph is required that has three of the data elements represented basically on the y axis and time as months along the x axis. So for each month there is a group of three columns representing the data...
1
1468
by: Red | last post by:
Ok, yada yada yada, I know this is the Access group, however, I need help in Excel :D Here's the thing, I'm exporting data to excel (From Access), adding code from a string, and executing the code... no biggie, I do it daily.. my superiors are high on Excel....
6
3168
by: Thelma Lubkin | last post by:
I am trying to modify an Access form that allows a user to specify the information s/he needs from a census-type database. The form's code builds a SQL statement from the user's request, and creates from this a record set that is used to populate a new Excel workbook. The form's code opens the new workbook and writes both a datasheet and a graph based on the data to it. The graph appears on the user's screen very briefly and then...
3
2046
by: hayuti | last post by:
Hi there This Question was posted on a wrong site. Just as introduction I am working in Access VBA where I coded a routine to retrive data from Access Database, exporting it on to Excel file (sucessful opens and posts the data on the required number of sheets) and finally is supposed to plot a scattered graph. At this stage the routine successful exports the data to excel but I am having a problem with the chart plotting part. Even...
3
2130
by: Jawad Rehman | last post by:
Hello everybody..... I have an excel file which is resided on server,there is some data on the cells .Now i want to generate dynamic graph on the basis of the data present in the excel file using ASP.NET. I have solution of this ,that i should use the Com component interop.microsoft.excel.but According to the specifaction of this Com Component.In order to
4
2764
by: Keith Wilby | last post by:
How controllable from Access VBA is Excel? I'm currently using automation to dump 2 columns of data into an Excel spreadsheet so that the end user can create a line graph based on it. Could the line graph be created from Access as part of the automation process? Is it also possible to rename the Excel worksheets from Access? Thanks. Keith.
0
1438
by: naish | last post by:
Hi, My code drawing a graph in excel sheet. There one colum for lower pressure and another one for upper pressure. Any howi can draw a series for one pressure but i am not able to draw two series one for lower and nother for upper in a single graph. My code is here Before this code i opened worksheet , imported the csv data and trying to plot it on the graph. Excel.ChartObjects chartObjs =...
16
5185
by: Phil Stanton | last post by:
I have a form with a button which is supposed to open an Excel file (With lots of Macros /VBA) in it. The Excel file gets it's data from the Access program Here is the code Private Sub Storage_Click() On Error GoTo Err_Storage_Click
0
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
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
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
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
9737
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
8737
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...
0
6562
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
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.