Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5978549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:31:54+00:00 2026-05-22T21:31:54+00:00

EDITED If you guys have a link that might help with this problem I’d

  • 0

EDITED

If you guys have a link that might help with this problem I’d really like to read it, because so far I haven’t seen anything very useful.

In access I’m trying to export arbitrary data to excel, create multiple charts (right now just working on a pie chart), format these charts and then send them to a blank (Chart) sheet. So far I’ve exported the data and am able to create the charts, I just have no idea how to format them.

The formatting I want to do is to get rid of the legend, put data labels with the name, value, and percentage, and move it to a “Chart” sheet.

Edit I am now able to get rid of the legend as well as insert the data labels with name, value and percentage. I am still stuck on moving the Chart object to a new sheet, code at bottom.

I’ve also tried to record a macro in excel, edit it slightly and then move it over to access but I keep erroring out, usually with an error similar to “This object doesn’t have that method”. Below I’ll include a test table that I might get and how I create the pie chart.

Code:

Function Excel_Export_Two_Column()
Dim db As DAO.Database, rs As DAO.Recordset
Dim WBO As Object, WSO As Object, WSO2 As Object, XLO As Object, oChart As Object
Dim x As Long, y As Long, z As Integer, strTab As String, strcompany As String
Dim endTable As Long
Dim tempName As String, tempNum1 As Long, tempNum2 As Long, totalEnd As Long

z = 1
Set db = CurrentDb()
Set rs = db.OpenRecordset("QRY2Col")

Set XLO = CreateObject("Excel.Application")
XLO.Application.Workbooks.Add

Set WBO = XLO.Application.ActiveWorkbook
Set WSO = WBO.Worksheets(1)
Set WSO2 = WBO.Worksheets(2)

WSO.Name = Left("export", 31)

For y = 0 To rs.Fields.Count - 1
    WSO.Cells(1, 1) = "Num"
    WSO.Cells(1, y + 2) = rs(y).Name
Next y

x = 1
Do While Not rs.EOF()
    x = x + 1
    WSO.Cells(x, 1) = x - 1
    For y = 0 To rs.Fields.Count - 1
        WSO.Cells(x, y + 2) = Trim(rs(y))
    Next y

    rs.MoveNext
    DoEvents
Loop

WSO.Cells.Rows(1).AutoFilter
WSO.Application.Cells.Select
WSO.Cells.EntireColumn.AutoFit

x = 1
Do While WSO.Cells(x, 1) <> ""
    x = x + 1
Loop

endTable = x - 1

WSO2.Cells(1, 1) = "Name"
WSO2.Cells(1, 2) = "Num"
totalEnd = 2
For x = 2 To endTable
    If (WSO.Cells(x, 2) <> "") Then
        tempName = WSO.Cells(x, 2)
        tempNum1 = WSO.Cells(x, 3)

        For y = 2 To totalEnd
            If (WSO2.Cells(y, 1) = tempName) Then
                tempNum2 = WSO2.Cells(y, 2)
                WSO2.Cells(y, 2) = tempNum1 + tempNum2
                Exit For
            ElseIf (y = totalEnd) Then
                WSO2.Cells(y, 1) = tempName
                WSO2.Cells(y, 2) = tempNum1
                totalEnd = totalEnd + 1
            End If
        Next y
    End If
Next x

Set oChart = WSO2.ChartObjects.Add(500, 100, 500, 300).Chart
oChart.SetSourceData Source:=WSO2.Range("A1").Resize(totalEnd - 1, 2)
oChart.ChartType = 5

strcompany = "Export"
If Dir(CurrentProject.Path & "\COLA_AR_" & Format(Date, "yyyymm") & "_XXX_" & strcompany & ".xlsx") <> "" Then
    Kill CurrentProject.Path & "\COLA_AR_" & Format(Date, "yyyymm") & "_XXX_" & strcompany & ".xlsx"
End If

Call WBO.SaveAs(CurrentProject.Path & "\COLA_AR_" & Format(Date, "yyyymm") & "_test_2_Col.xlsx")


WBO.Close savechanges:=True
Set WBO = Nothing

XLO.Application.Quit
Set XLO = Nothing

rs.Close
db.Close
End Function

Table: Note that this table is in a Query (named “QRY2Col”) in Access

Field1          Field2
CTOD            64646515
BFTBC2          6656532
WTOW            451512355
DT3             684321818
STC2            652553548
BFTBC2          12
DT3             84954987
ATCR            99999999
CTOD            64185435
BFTBC2          321569846
STC2            6543518
STC2            3518684
ATCR            35481354

Code for data labels

Set oChart = WSO2.ChartObjects.Add(500, 100, 500, 300).Chart
oChart.SetSourceData Source:=WSO2.Range("A1").Resize(totalEnd - 1, 2)
' Number corresponds to a pie chart
oChart.ChartType = 5

' Adds data Labels
oChart.SeriesCollection(1).HasDataLabels = True

' Format chart
oChart.SeriesCollection(1).DataLabels.ShowCategoryName = True
oChart.SeriesCollection(1).DataLabels.ShowPercentage = True
oChart.SeriesCollection(1).HasLeaderLines = True
oChart.Legend.Delete

Attempted code to move chart

Below is an example of what I recorded (edited by adding “oChart”) but this still doesn’t work. The problem that gets highlighted is the “xlLocationAsNewSheet” and VBA says that the “Variable is not defined”.

oChart.Location Where:=xlLocationAsNewSheet

Thank you,

Jesse Smothermon

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:31:55+00:00Added an answer on May 22, 2026 at 9:31 pm

    For the last part, try this:

    oChart.Location Where:=1
    
    ' xlLocationAsNewSheet = 1
    ' xlLocationAsObject = 2
    ' xlLocationAutomatic = 3
    

    As David pointed out, you cannot use the types/enums etcetera defined in the Excel object library without a reference to it, thus you are stuck using integer constants instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

--edited for clarity (hopefully) I have an XML file that looks something like this:
I have a problem: I have a textarea on my page that looks like
hey guys m running into a problem, i have a forloop n in that
Okay I'm looking for some assistance I have researched and read posts that pertain
Hi this question or problem i have its very hard i have search and
[edited] I am trying to make a script that downloads a file, the problem
I have a problem with .Net's RichTextBox control. It seems that it doesn't support
can't find an answer to this one... I have a form that detects changed
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
Edited: SOLUTION FOUND. This is strange and not the best solution, but I just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.