error 1004

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I wrote a procedure attached on a bottom of a access form which is for
selecting some data and exporting them to excel and plotting a chart. The
procedure work alternatively...that it work for the first time, then an error
of 1004 of Method 'ActiveChart' of object '_Globel' failed for the second
time then it work for the third time and so on. The below is the procedure
fragment. Can any one give me an idea?

Dim oChart As Chart

Set oSheet2 = oBook.Worksheets(2)
oSheet2.Select
oSheet2.Name = "Chart"
oSheet2.Range("A1").Select
Set oChart = oBook.Charts.Add

ActiveChart.ChartType = xlLineMarkers " the error was highlight there.
 
Warren Siu wrote in message
I wrote a procedure attached on a bottom of a access form which is
for selecting some data and exporting them to excel and plotting a
chart. The procedure work alternatively...that it work for the first
time, then an error of 1004 of Method 'ActiveChart' of object
'_Globel' failed for the second time then it work for the third time
and so on. The below is the procedure fragment. Can any one give me
an idea?

Dim oChart As Chart

Set oSheet2 = oBook.Worksheets(2)
oSheet2.Select
oSheet2.Name = "Chart"
oSheet2.Range("A1").Select
Set oChart = oBook.Charts.Add

ActiveChart.ChartType = xlLineMarkers " the error was highlight
there.

The most likely culprit, is the non qualified reference to the active
chart. It will need to be qualified through the relevant excel
objects in stead. I don't have much knowledge about these kind of
Excel objects, but I'd quess the newly created chart object could
be used

Set oChart = oBook.Charts.Add

oChart.ChartType = xlLineMarkers

All references and usage of Excel objects, methods and properties need
to be performed by "proper" referencing - i e - for instance through
the
object variables used.
 
Back
Top