473,756 Members | 5,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access & Excel Interoperabilit y woes

4 New Member
I am trying to dump data from an access query into excel so I can pretify it. I found sample code from an old access 97 book (The version of access in use)and tinkered it into working.

Well sort of. The error I get is usually a "Object Required" error, and it highlights the bolded section below. I have been through this thing backwards and forth and cannot figure it out. I am new to this whole thing, so be easy on me.

Thanks!

Alex

----------code pasted below------------
Expand|Select|Wrap|Line Numbers
  1. Private Const conQuery = "alexpartcountrial"
  2. Private Const conSheetName = "Part Count"
  3.  
  4. Public Sub CreateExcelChart()
  5.  
  6.     Dim rst As ADODB.Recordset
  7.  
  8.     ' Excel object variables
  9.     Dim xlApp As Excel.Application
  10.     Dim xlBook As Excel.Workbook
  11.     Dim xlSheet As Excel.Worksheet
  12.     Dim xlChart As Excel.Chart
  13.  
  14.     Dim i As Integer
  15.  
  16.     ' Create Excel Application object.
  17.     Set xlApp = New Excel.Application
  18.  
  19.     ' Create a new workbook.
  20.     Set xlBook = xlApp.Workbooks.Add
  21.  
  22.     ' Get rid of all but one worksheet.
  23.     xlApp.DisplayAlerts = False
  24.     For i = xlBook.Worksheets.Count To 2 Step -1
  25.         xlBook.Worksheets(i).Delete
  26.     Next i
  27.     xlApp.DisplayAlerts = True
  28.  
  29.     ' Capture reference to first worksheet.
  30.     Set xlSheet = xlBook.ActiveSheet
  31.  
  32.     ' Change the worksheet name.
  33.     xlSheet.Name = conSheetName
  34.  
  35.     ' Create recordset.
  36.     Set rst = New ADODB.Recordset
  37.     rst.Open Source:=conQuery, ActiveConnection:=CurrentProject.Connection
  38.  
  39.     With xlSheet
  40.         ' Copy field names to Excel.
  41.         ' Bold the column headings.
  42.         With .Cells(1, 1)
  43.             .value = rst.Fields(0).Name
  44.             .Font.Bold = True
  45.         End With
  46.         With .Cells(1, 2)
  47.             .value = rst.Fields(1).Name
  48.             .Font.Bold = True
  49.         End With
  50.  
  51.         ' Copy all the data from the recordset
  52.         ' into the spreadsheet.
  53.         .Range("A2").CopyFromRecordset rst
  54.  
  55.         ' Format the data.
  56.         .Columns(1).AutoFit
  57.         .Columns(2).AutoFit
  58.         .Columns(3).AutoFit
  59.  
  60.     End With
  61.  
  62.     ' Create the chart.
  63.     Set xlChart = xlApp.Charts.Add
  64.     With xlChart
  65.         .ChartType = xl3DBarClustered
  66.         .SetSourceData xlSheet.Cells(1, 1).CurrentRegion
  67.         .PlotBy = xlColumns
  68.         .Location _
  69.          Where:=xlLocationAsObject, _
  70.          Name:=conSheetName
  71.     End With
  72.  
  73.     ' Setting the location loses the reference, so you
  74.     ' must retrieve a new reference to the chart.
  75.     With xlBook.ActiveChart
  76.         .HasTitle = True
  77.         .HasLegend = False
  78.         With .ChartTitle
  79.             .Characters.Text = conSheetName & " Chart"
  80.             .Font.Size = 16
  81.             .Shadow = True
  82.             .Border.LineStyle = xlSolid
  83.         End With
  84.         With .ChartGroups(1)
  85.             .GapWidth = 20
  86.             .VaryByCategories = True
  87.         End With
  88.         .Axes(xlCategory).TickLabels.Font.Size = 8
  89.         .Axes(xlCategoryScale).TickLabels.Font.Size = 8
  90.      End With
  91.  
  92.     ' Display the Excel chart.
  93.     xlApp.Visible = True
  94.  
  95. ExitHere:
  96.     On Error Resume Next
  97.     ' Clean up.
  98.     rst.Close
  99.     Set rst = Nothing
  100.     Set xlSheet = Nothing
  101.     Set xlBook = Nothing
  102.     Set xlApp = Nothing
  103.     Exit Sub
  104.  
  105. End Sub
May 11 '07 #1
0 1509

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

Similar topics

38
2307
by: Remco Groot Beumer | last post by:
Hello, I'm trying to decide if the following situation would be workable: Generate an MS Access Front End (which will run localy on client computers), which will link to a DBMS (SQL server or Oracle). As far as I know there will be approx. 30 till 40 users max working on the database. I think approx. 25 users will actually enter data (others will be mostly reporting and viewing). I don't really know the network capacity.
11
4055
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it again, Excel hangs. OR if I open Excel again (say from a desktop icon) before I close Access, Excel hangs. (this has happened for both 97 & 2000 for me) I of course thought that I mustn't be unloading a variable properly.
1
3604
by: u7djo | last post by:
Hi, I'm currently building a function in Access that creates an Excel spreadsheet but it doesn't look like the Excel object is being destroyed correctly as the Excel module is still showing in the task manager and I'm unable to open the spreadsheet without first closing down Access. Can anyone help!? Dave Public Function CreateInputSheet(scriptName As String, ParamArray
0
3731
by: TheCoder | last post by:
I am making a D-base with web conectivity for my class project. I have everything working but the subit button sends the data to the correct fields but afterwards it wants to reproduce new blank text boxes how do I stop this and how would I code it to redirect to a thank you page. All with out the help of a web server this has to br ran from the desktop and with in IE with a local directory. Pleas help I am stuck. here is the code! ...
5
2471
by: David C. Allen | last post by:
I have a vb.net app that is controling excel 2000 thru the com interop interface. I have referenced the excel 9.0 library and have cut down the code in the problem subroutine to this: Dim objExcelApp As New Excel.Application objExcelApp.Quit() objExcelApp = Nothing The problem is excel is hanging in memory and has to be closed by the task
0
1644
by: Pradnya Patil | last post by:
Hi , I need to export some of the reports to MS EXCEL & MS WORD in a WEB APPLICATION.I also need to LOCK some of the Columns in EXCEL-sheet.Right now I need to run the Interoperability setup on the machine where the software will run.The machine
0
6744
by: Vijay | last post by:
Prep Courses for International Certifications, CSTE & CSQA & ISEB & ISTQB &Business Analyst & SOA Certifications in HYDERABAD. After receiving overwhelming response to our last 50+ batches, SPECTRAMIND SOLUTIONS now announces a new batch of Prep Courses for CSQA & CSTE& ISEB & ISTQB & Business Analyst & SOA so as to prepare you thoroughly for the most prestigious certification exams conducted by International organizations. We...
4
4399
by: Suzette | last post by:
I have an excel file that automatically updates when opened, pulling information from an Access database into into various pivot tables. I created a macro in Access to perform various necessary functions with the data. I want to be able to open an Access form that I created, and then hit a button that will run the macros and that will open the excel database. The only problem that I am having is that when the excel file opens and tries...
0
1345
by: Noob | last post by:
Hello, I created an ERP based custom report using Access '03 & Excel '03. I developed an Access query that pulls the required data from the ERP (Progress) database via link tables. I use Excel to call this query and pull the resulting data into a spreadsheet complete with running balance formulas and conditional formatting. There is neither SQL, nor VB code involved. The problem that I am running into is that Excel 2007 does not...
0
9462
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
10046
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...
1
9857
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9722
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
8723
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
7259
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
6542
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
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2677
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.