Access 2007: error setting axes minimum value in Excel file

fradaems

New Member
Joined
Oct 17, 2015
Messages
4
I've been searching for the cause of an error all day, but can't see it.

Summary: an Access form creates an Excel file with 2 worksheets: one for data and another one for a graph. Once the graph is completed it is saved as a .png file. All working fine, except one thing. I want all graphs to have the Y axe start at zero. Most do, some don't (because of minimal difference between min. and max. value). Hence, I wanted to set the minimal value to always be zero.

Coding (parts of the function):

a) related definitions
<code>
Dim oXL As Object ' Excel application
Dim oBook As Object ' Excel workbook
Dim oSheet1 As Object ' Excel Worksheet
Dim oSheet2 As Object ' Excel Worksheet
Dim oChart As Object ' Excel Chart
Dim cNumRows As Integer ' Number of Series
</code>
b) creation of graph (note oSheet1 is the worksheet containing the 2 columns of information (column A a date, column B a percentage) - this coding works
<code>
oBook.Sheets.Add
Set oSheet2 = oBook.Worksheets.Item(1)
Set oChart = oSheet2.ChartObjects.Add(1, 1, 900, 400).Chart
oChart.SetSourceData Source:=oSheet1.Range("A2").Resize(cNumRows - 1, 2)
With oSheet2.ChartObjects(1).Chart
.HasTitle = True
.ChartTitle.Text = recdef![Categorie] & " - ( " & Format(counter, "0") & " fondsen )"
.SeriesCollection(1).Name = "Percentage"
End With
</code>
c) various attempts to set the Y axe value to zero (changing some lines from comment to code or reversed). All fail on the 'With .Axes' coding line (method failed - sorry my software is in Dutch language so I don't know the exact message in English). The 3 first commented lines contain what the Excel macro gave when recording the manual change, which doesn't work either).
<code>
' ActiveSheet.ChartObjects("Grafiek 1").Activate
' ActiveChart.Axes(xlValue).select
' ActiveChart.Axes(xlValue).MinimumScale = 0

' With oChart
With oSheet2.ChartObjects(1).Chart
With .Axes(xlValue)
' With .Axes(xlValue, xlPrimary)
.MinimumScale = 0
End With
End With

TIA for your help!

</code>
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Just taking a stab here. oChart As Object might have to be oChart as ChartObject. Also, I think ChartObjects is a collection, not a specific chart, so I don't think you can refer to it with an index the way you are. The index would be for the chart object. I think that's why you're getting a message about a failed method. Maybe after activating the correct sheet:

Code:
With
  ActiveSheet.ChartObjects.oChart.Chart(1).Axes
  .MinimumScale =
  .MaximumScale = 
  .MajorUnit = 
End With
I would not bet money on my air code, though.;)
 
Upvote 0
Thanks for your help. I meanwhile had given up and applied a simple workaround instead. I've added an additional group of data (i.e. last date plus one with a zero percentage) and the graph now shows what I wanted it to look like, starting with zero minimum value on the Y axe.
 
Upvote 0
Where are you declaring the Excel VBA constants xlValue and xlPrimary?
 
Upvote 0
Thanks for your help, which gives me an idea. It's not declared anywhere. I should maybe add a reference to Excel? I see a 'Microsoft Excel 12.0 Object Library' which is not ticked for the moment. I'll give it a try tomorrow (where I live it's high time to go to bed now - working day tomorrow again).
 
Upvote 0
You don't really need to add a reference to Excel.

Just goto the Object Browser in Excel VBA, search for xlValue and xlPrimary and copy their declarations to your Access code.
 
Upvote 0
Adding the reference mentioned in my previous message listed above did solve the problem!
 
Upvote 0
Glad to hear that.:)

I've had similar problems in the past when using late-binding to automate other applications.

One thing I found invaluable was to add Option Explicit at the top of every module using the Require variable declaration setting under Tools>Options.

With that set up any undeclared (or misspelt) variables were soon flagged up.
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,559
Members
449,171
Latest member
jominadeo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top