473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Runtime Error 1004 "Method Range Of Object Global Failed"

Hey all,

I have a piece of code that dumps a bunch of data into a spreadsheet. Also rearranges it into a pivot table and then graphs the pivot table as well so my boss can get a clear view of the data.

This question is two part. One, I seem to be getting the title error at the starting line stating:
Expand|Select|Wrap|Line Numbers
  1.         oSheet.Range(rng).Select
  2.          With Selection
  3.              shp.Left = .Left
  4.              shp.Top = .Top
  5.              shp.Width = .Width
  6.              shp.Height = .Height
  7.          End With
What is driving me insane, is that it only happens sometimes. Like half the time.

The other issue I'm having (and I am very novice I will admit) is that I don't know how to properly place the pivot chart I am creating at the end of the below code... what I would like to do is have it on a different sheet but I have tried a few things without results. I'm just very confused, feeling burnt out and I have a day off work here so I was wondering if maybe some of you can confuse me!

Expand|Select|Wrap|Line Numbers
  1. Public Sub CreateDAOChartM(strSourceName As String, _
  2.       strChartLabel As String)
  3. 'On Error GoTo unexError
  4. Dim i As Integer
  5. Dim db As DAO.Database
  6. Dim rs As DAO.Recordset
  7. Set db = CurrentDb
  8. Set rs = db.OpenRecordset(strSourceName)
  9.  
  10. Dim oApp As New Excel.Application
  11. Dim oBook As Excel.Workbook
  12. Dim oSheet As Excel.Worksheet
  13. Dim oSheetMain As Excel.Worksheet
  14.  
  15. Dim FinalRow As Long
  16. Dim FinalCol As Long
  17.  
  18. Dim oChartObj As Excel.Chart
  19. Dim oColPoint As Excel.Point
  20. Dim oSourceRange As Excel.Range
  21.  
  22.  
  23. Set oBook = oApp.Workbooks.Add
  24.  
  25. 'This used to set the Worksheet to the first page of the sheet
  26. Set oSheet = oBook.Worksheets(1)
  27.  
  28. 'OLD CREATION
  29. 'populate sheet 2 with data
  30.     Dim iNumCols As Integer
  31.     iNumCols = rs.Fields.Count
  32.     For i = 1 To iNumCols
  33.         oSheet.Cells(1, i).Value = rs.Fields(i - 1).Name
  34.     Next
  35.     'Add Data to sheet
  36.     oSheet.Range("A2").CopyFromRecordset rs
  37.     'format header as bold and autofit columns
  38.     With oSheet.Range("a1").Resize(1, iNumCols)
  39.         .Font.Bold = True
  40.         .EntireColumn.AutoFit
  41.     End With
  42.  
  43. Dim pt As PivotTable
  44. Dim pf As PivotField
  45.  
  46.  
  47. 'oBook.PivotCaches.Create(xlDatabase, oSheet.UsedRange).CreatePivotTable TableDestination:="", TableName:="PivotTable1"
  48. oBook.PivotCaches.Create(xlDatabase, oSheet.UsedRange).CreatePivotTable TableDestination:="", tableName:="PivotTable1"
  49. oSheet.PivotTableWizard TableDestination:=oSheet.Cells(1, 5), tableName:="Pivot1"
  50.  
  51. Set pt = oSheet.PivotTables("Pivot1")
  52. Set pf = pt.PivotFields(strChartLabel)
  53.  
  54. 'Going to have to figure out how to get copper out
  55. oSheet.PivotTables("Pivot1").AddFields ColumnFields:=Array("equipmentID", "sampleDate")
  56.  
  57. With pf
  58.         .Orientation = xlDataField
  59.         .Function = xlAverage
  60. End With
  61.  
  62.          pt.PivotFields("equipmentID").Orientation = xlColumnField
  63.          pt.PivotFields("sampleDate").Orientation = xlRowField
  64.  
  65.  
  66.          Dim shp As Shape
  67.          Set shp = oSheet.Shapes.AddChart(xlColumnClustered)
  68.          shp.Chart.SetSourceData Source:=oSheet.PivotTables(1).TableRange2, _
  69.                                PlotBy:=xlColumns
  70.  
  71.          With shp.Chart.Axes(xlCategory)
  72.             .TickLabels.Orientation = 80
  73.          End With
  74.  
  75.         Dim rng As String
  76.         rng = (Replace(("A" & Str(rs.RecordCount + 5) & ":V" & Str(rs.RecordCount + 32)), " ", ""))
  77.  
  78.         oSheet.Select
  79.         oSheet.Activate
  80.         oSheet.Range(rng).Select
  81.          With Selection
  82.              shp.Left = .Left
  83.              shp.Top = .Top
  84.              shp.Width = .Width
  85.              shp.Height = .Height
  86.          End With
  87.  
  88.  
  89.  
  90.          With shp.Chart.PivotLayout.PivotTable
  91.              .PivotFields("equipmentID").Orientation = xlColumnField
  92.              .PivotFields("sampleDate").Orientation = xlRowField
  93.              .GetPivotData
  94.          End With
  95.          shp.Chart.ChartType = xlColumnClustered
  96.          shp.Chart.Refresh
  97.          oApp.Visible = True
  98.          shp.Chart.ChartType = xlColumnClustered
  99.          shp.Chart.Refresh
  100.  
  101. 'Display
  102. 'On Error GoTo closeerror:
  103. oApp.Visible = True
  104. oApp.UserControl = True
  105.  
  106. 'close out everything
  107.  
  108. rs.Close
  109. db.Close
  110.  
  111.  
  112. Exit Sub
  113. unexError:
  114. MsgBox Str$(Err.Number)
  115.  
  116. On Error GoTo closeerror:
  117. 'close out everything
  118.  
  119. rs.Close
  120. db.Close
  121. closeerror:
  122. Exit Sub
  123. End Sub
Dec 4 '09 #1
0 3397

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

Similar topics

0
by: camaro77 majau via DotNetMonster.com | last post by:
Sorry by my english but i'm from spain. I have a problem and after search by the web i have know that is due by framework. The message is : setup error "failed to load ressouces from resource...
0
by: John Phelan | last post by:
I have created a front-end application and back-end database. Everytime that I opened the program in the past, it open just fine with no errors when linking to the back-end tables. lately, I get...
0
by: John Phelan Cummings | last post by:
I have created a front-end application and back-end database. Everytime that I opened the program in the past, it open just fine with no errors when linking to the back-end tables. Lately, I...
4
by: John Phelan | last post by:
I have created a front-end application and back-end database. I have code that automatically links the front-end application to the back-end database for whenever I provide a patch or upgrade....
4
by: John Phelan | last post by:
Continue to get error message. Here is an update of my problem and everything that I have done to correct it. I have created a front-end application and back-end database. I have code that...
10
by: Abel | last post by:
I have this code string theClassName = "Rules.FillListBox.FillListBox" + theType + ", Rules" Type theClass = Type.GetType(theClassName) Object o = Activator.CreateInstance(theClass) object...
2
by: =?Utf-8?B?QmFkaXM=?= | last post by:
I'm doing a server side automation(I know it's bad but..) and its working fine locally and when accessing it from a remote machine using web browser is was giving me this error"Retrieving the COM...
3
by: =?Utf-8?B?QmFkaXM=?= | last post by:
I'm doing a server side automation(I know it's bad but..) and its working fine locally and when accessing it from a remote machine using web browser is was giving me this error"Retrieving the COM...
5
by: monu121 | last post by:
hi, i am getting one error "Object Does Not Support This Property or Method..." when i am using my dll file actuly i am calling my dll file in product. i am using vb 6.0. if any one is...
10
RMWChaos
by: RMWChaos | last post by:
WinVista/IE7 I am getting some weird errors only in IE7, but not in FF2.0.0.8 or NN9. It even happens on this website when I click "Sign In". The error is: "A Runtime Error has occurred."...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.