473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Runtime Error 1004 "Method Range Of Object Global Failed"

29 New Member
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 3416

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

Similar topics

0
2173
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 file please check your setup" It only appears when i'm using a p2p program called elephant,who needs framework to run.some month ago I instaled for...
0
1429
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 the following error message whenever I open my application: ERROR: "Method 'Connection' of object '_Current Project' failed. Check to see if...
0
1472
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 get the following error message whenever I open my application: ERROR: "Method 'Connection' of object '_Current Project' failed. Check to see if...
4
3836
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. Everytime that I opened the program in the past using either Access 2002 and 2003, it open just fine with no errors when linking to the back-end...
4
2362
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 automatically links the front-end application to the back-end database for whenever I provide a patch or upgrade. Everytime that I opened the program...
10
2161
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 parameters = new object parameters = elListBox parameters = (IList)Session theClass.GetMethod("fill").Invoke(o, (object)parameters)
2
6479
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 class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005". so I configured the...
3
2973
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 class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005". so I configured the...
5
2956
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 knowing about this so plz help me. thanks & regards monu121
10
13287
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." "Line:xxx" "Error: Object expected" and Debug says: "Microsoft JScript runtime error: Object expected."
0
7943
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...
1
7456
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7786
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...
0
6022
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...
1
5359
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...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1919
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
1
1044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
743
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...

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.