473,506 Members | 17,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a slope formula for Access

1 New Member
Hi everyone,

I need some help with a slope formula.

My company uses a spreadsheet where one line uses the SLOPE formula. I found from my research on the internet that there is no similar function type in Access 2003.

I found a thread in BYTES from a kux who asked to, Calculate slope of a data set or trend line

A <email removed> answered kux question, but I have no clue what his formula meant. I had some others look at the formula and they left scratching their heads.

I just want to find out how to write a formula which will give me the slope.

Below is the information that is on our Excel spreadsheet which covers a 5 month period and the sales of two different products. At the bottom of each is the SLOPE calculated from Excel.

Thank you all for your help

Product #1

Period Sales

1 5
2 2
3 40
4
5 10

Slope 3 (rounded)


Product #2

Period Sales

1 6271
2 6817
3 9202
4 7629
5 11721

Slope 1171.2 (rounded)
May 26 '11 #1
9 8345
NeoPa
32,557 Recognized Expert Moderator MVP
It is possible to use Excel Functions in Access. Hopefully this will help.
May 26 '11 #2
Rabbit
12,516 Recognized Expert Moderator MVP
Slope runs a linear regression on the data. It is most likely returning the Pearson coefficient. The formula for the Pearson coefficent is



You can find more info on the formula here http://en.wikipedia.org/wiki/Pearson...on_coefficient
May 27 '11 #3
Rabbit
12,516 Recognized Expert Moderator MVP
I was wrong. According to the microsoft website, it uses a slightly different formula.



http://office.microsoft.com/en-us/ex...005209264.aspx
May 27 '11 #4
ADezii
8,834 Recognized Expert Expert
As hinted to by NeoPa in Post #2, you can:
  1. Collect your Access Data and populate 2 Arrays representing your known Y and X Values.
  2. Pass those Arrays to Excel's Slope() Function for processing via Automation Code.
  3. I know of no method to do this entirely within the confines of Access.
  4. Using Data from your 2nd Example:
    Expand|Select|Wrap|Line Numbers
    1. Dim aintYs(1 To 5) As Integer
    2. Dim aintXs(1 To 5) As Integer
    3. Dim intCtr As Integer
    4. 'Make sure to 1st set a Reference to the Microsoft Excel XX.X Object Library
    5. Dim objExcel As Excel.Application
    6.  
    7. Set objExcel = CreateObject("Excel.Application")
    8.  
    9. For intCtr = 1 To 5
    10.   aintYs(intCtr) = intCtr
    11.     Select Case intCtr
    12.       Case 1
    13.         aintXs(intCtr) = 6271
    14.       Case 2
    15.         aintXs(intCtr) = 6817
    16.       Case 3
    17.         aintXs(intCtr) = 9202
    18.       Case 4
    19.         aintXs(intCtr) = 7629
    20.       Case 5
    21.         aintXs(intCtr) = 11721
    22.     End Select
    23. Next
    24.  
    25. MsgBox "The Slope of know Ys and Xs is: " & objExcel.Application.Slope(aintYs, aintXs)
May 28 '11 #5
NeoPa
32,557 Recognized Expert Moderator MVP
There may be some problems with that ADezii :-(

First, the article is about using another application (but not automation). It is there to illustrate that such usage of functions is much more straightforward than having to set up automation and actually open up an instance of the related application that needs to be closed after use. A reference is all that is required.

Next, although the OP never says so explicitly in the question (which is certainly unfortunate), the SLOPE function is an Excel Worksheet function specifically (those that can be used in cell formulas rather than those available to VBA). As such I think your line #25 would fail (I tried it and it failed for me). What you need is a reference to Excel's WorksheetFunction object :
Expand|Select|Wrap|Line Numbers
  1. Excel.WorksheetFunction.Slope(...)
No Excel application required.

While referring to your code, isn't it a shame that VBA has such trouble with handling arrays. The Array() function returns an array, but the returned result cannot be assigned directly to a DIMmed array variable. How inconvenient is that?
May 28 '11 #6
ADezii
8,834 Recognized Expert Expert
@NeoPa - I executed both Versions of the Code (mine and yours) against Excel's Sample Data and Results in the Help File. When rounded to 6 significant Digits, the results are exactly the same. I cannot see where it is failing on your end.
May 28 '11 #7
NeoPa
32,557 Recognized Expert Moderator MVP
I didn't express that quite accurately ADezii. I meant I couldn't even find the routine at that address. Intellisense and the Object Browser both indicated that it was only found as a property of the .WorksheetFunctions object (not within the Excel.Application object). Are you saying that regardless of that, the code does actually execute (I didn't want to set up the whole environment just to check something which the Intellisense + Object Browser indicated was not found in that place but I will later anyway as you've called that into question)?

BTW. The Help system gave no clues as it didn't find it within VBA Help at all - Only from Excel itself. This further indicated for me that it shouldn't be available directly from the Excel.Application object. Still, only testing will tell (which I'll do as soon as I have a spare minute).
May 28 '11 #8
ADezii
8,834 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. Dim aintYs(6) As Integer
  2. Dim aintXs(6) As Integer
  3. Dim intCtr As Integer
  4.  
  5. Dim objExcel As Excel.Application
  6. Set objExcel = CreateObject("Excel.Application")
  7.  
  8. For intCtr = 0 To 6
  9.   Select Case intCtr
  10.     Case 0
  11.       aintYs(intCtr) = 2
  12.       aintXs(intCtr) = 6
  13.     Case 1
  14.       aintYs(intCtr) = 3
  15.       aintXs(intCtr) = 5
  16.     Case 2
  17.       aintYs(intCtr) = 9
  18.       aintXs(intCtr) = 11
  19.     Case 3
  20.       aintYs(intCtr) = 1
  21.       aintXs(intCtr) = 7
  22.     Case 4
  23.       aintYs(intCtr) = 8
  24.       aintXs(intCtr) = 5
  25.     Case 5
  26.       aintYs(intCtr) = 7
  27.       aintXs(intCtr) = 4
  28.     Case 6
  29.       aintYs(intCtr) = 5
  30.       aintXs(intCtr) = 4
  31.   End Select
  32. Next
  33.  
  34. 'Both approaches will generate the same Results
  35. MsgBox "The ADezii Slope of known Ys and Xs is: " & _
  36.         FormatNumber(objExcel.Application.Slope(aintYs, aintXs), 6)
  37. MsgBox "The NeoPa Slope of known Ys and Xs is: " & _
  38.         FormatNumber(Excel.WorksheetFunction.Slope(aintYs, aintXs), 6)
May 28 '11 #9
NeoPa
32,557 Recognized Expert Moderator MVP
I got time to run your code ADezii. Obviously, you were absolutely correct in saying it worked. Excel.Application.Slope() also works of course, as well as objExcel.Slope().

Notwithstanding that, I still couldn't find any documented support of using it that way, no matter where I looked (within the application itself - I'm not saying I wouldn't have found anything on the web - it's here now after all).
May 28 '11 #10

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

Similar topics

2
1396
by: Jeff Janoian | last post by:
I have a need to have an end user enter information into a database from the web and have them be able to produce a pdf document/application to be able to download in the pdf format. I need to...
4
3171
by: musicloverlch | last post by:
I used to be able to create PDFs, automatically save them to a file, and mail them out to people. This was on Access 97 with Windows NT. We've changed to Windows XP and Access 2003. Doesn't work...
3
2387
by: Eric Carr | last post by:
I have been trying to create a table in an Access database via a VB.NET program and I am running into a problem defining an autoincrement field. I am getting an error saying "Property 'Item' is...
2
2670
by: MagicalDreams | last post by:
Hello I am sending data from access 2003 to Excel I then want to create a total sum for the data I have sent I can manage this if the data length is always the same length which it is not this...
0
1075
by: farhad | last post by:
Hi Could you help me , how can I get backup automaticly by timming (like as each 15 min) from access database if my access have password ?
4
1172
by: mabzkie | last post by:
how can i generate a new database using vb? i want to create a MS access database. anyone, please give me an idea. thank you for your time.
3
8265
by: daokfella | last post by:
In my solution, I have a project that is my data access layer. This layer simply consists of strongly-typed datasets created by dragging tables from the server explorer into the dataset designer....
5
2993
by: mattkorguk | last post by:
Hi, Following the introduction of an appointment booking system in Access I've now given myself another issue. As I'm sending lots of appointments out I'm also then getting lots of the same...
2
1967
by: ernil | last post by:
Hi, I'm using VB 6 and MS Access. My problem is how to create a relationship in Access using VB 6. Thanks. - ernil
3
2128
by: mulamootil | last post by:
Hi friends, I am new to access and I need to create a report. Please pardon me for such a long post.Appreciate your patience. I have a table in Access (MyTable) with data about products...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7308
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,...
1
7023
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...
0
5617
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,...
0
4702
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...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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 ...
0
410
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...

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.