473,462 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Excel Functions in Access

NeoPa
32,556 Expert Mod 16PB
Many of us have noticed that there are some very useful functions available to you when using Excel, but these same functions are not available, as standard, in Access.
A particular issue I had recently (and I know others have come across this recently too) is rounding up and down. I know the Excel ROUNDUP() function rounds away from zero rather than upwards specifically, but is still useful in most circumstances.

To allow an Access database to use Excel (and by extension other Office libraries) you need to make the library available (this is on a database level rather than an Access installation level so be aware) simply :
  1. Open (or switch to) the VBA Window (Alt-F11).
  2. From the menus select Tools / References...
  3. Find the relevant library (in this specific case it will be Microsoft Excel 9.0 Object Library for Access 2000 which I'm using here, or whichever is right for your current version of Office).
While you're doing that you'll probably notice a whole bunch of other available references (libraries) which are available to link to.

This will save reproducing a bunch of functions which you may already be familiar with but find, to your disappointment, are not natively available in Access.

When I originally set this up I did some testing badly and thought that the Excel functions were available to SQL in a database that had the Excel library referenced. I subsequently discovered that not to be the case.

However, Public functions in your database are accessible to Jet SQL so if you have a requirement to implement an Excel function it is still possible to do so by the expedient of creating an encapsulating function (defined as Public in your database) which, itself, calls the Excel function. The VBA code in the database CAN access the Excel libraries. It is only Jet SQL that cannot.

Posted by Scott Price

This is a specific example of an Excel function; Forecast(). Called from a VBA code module in Access. (Developed using Access 2003).

Expand|Select|Wrap|Line Numbers
  1. Public Function xlForeCast() As Double
  2.  
  3. Dim MyDate As Integer 'Will be the point for which you are forecasting, in this case 2007
  4. Dim MyRange() As Variant 'Will be the independent element of the forecast function
  5. Dim MyRange1() As Variant 'Will be the dependent element of the forecast function
  6. Dim MyArray() As Variant 'Temp array to hold the query result set values before being split into the two preceding arrays
  7. Dim db As DAO.Database
  8. Dim rs1 As DAO.Recordset
  9. Dim ls As Integer 'Temp variable to count the rows in the list
  10.  
  11.  
  12. Set db = CurrentDb()
  13. Set rs1 = db.OpenRecordset("qryGetHistory") 'Opens the query that feeds the data
  14.  
  15.     With rs1
  16.         .MoveFirst
  17.         .MoveLast
  18.         ls = .RecordCount
  19.         .MoveFirst
  20.         MyArray() = .GetRows(ls) 'Populate the temporary array with the query results
  21.     End With
  22. 'Split the required data into two arrays, drawing from columns two and three in the query/array
  23. MyRange() = Array(CInt(MyArray(1, 0)), CInt(MyArray(1, 1)), CInt(MyArray(1, 2)), CInt(MyArray(1, 3)), CInt(MyArray(1, 4)))
  24. MyRange1() = Array(CInt(MyArray(2, 0)), CInt(MyArray(2, 1)), CInt(MyArray(2, 2)), CInt(MyArray(2, 3)), CInt(MyArray(2, 4)))
  25. MyDate = CInt(DatePart("yyyy", "July 30")) 'Set the Desired point to forecast for
  26. rs1.Close
  27. Set rs1 = Nothing 'Reset the recordset, releasing memory
  28. Set db = Nothing
  29.  
  30.     xlForeCast = Excel.WorksheetFunction.Forecast(MyDate, MyRange1, MyRange) 'Calls the Excel forecast function
  31.  
  32. Erase MyArray 'Reset the Arrays to zero, releasing memory
  33. Erase MyRange
  34. Erase MyRange1
  35. End Function
Oct 11 '07 #1
0 18736

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

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
1
by: v_verno | last post by:
Good day, I have a web page that shows info retrieved from a MySQL db and I would like to convert all these data into an .XLS file. Have searched the net high and low but seems that I'm unable to...
3
by: info | last post by:
After using clipboard functions in Excel controlled from Access VBA, Excel doesn't quit when I use the following ExcelApp.Quit Set ExcelApp = Nothing If I don't use the clipboard functions in...
10
by: Steve | last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains custom functions. I believe I need to use COM interop to allow VBA code in Excel 2002 to access it. I've studied...
4
by: David_from_Chicago | last post by:
What I am trying to do is to simulate the LINEST functionality from Excel in Access through VBA. When I use LinEst in Excel I can get back five statistical results. Here are is the formula array...
5
by: billelev | last post by:
Hi there. I need to perform a number of financial calculations within a database I am creating. Rather than writing my own functions, I figured it would be worthwhile to use the functions that...
2
by: paigenoel | last post by:
I was wondering how you can add a function (acos) which exists in MS Excel into MS Access 2003? I need several functions, one of which is ACOS. My formula work well in Excel and now I need to use it...
5
ADezii
by: ADezii | last post by:
Periodically, the same or similar question appears in our Access Forum: How can I use Excel Functions within Access? For this reason, I decided to make this Subject TheScripts Tip of the Week. In...
4
by: drt | last post by:
NEDERLANDS: Hallo, Ik heb eigen functies gemaakt in access, die werken perfect in de access query. Zodra ik echter vanuit excel een draaitabel maakt naar de access query (als een externe...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
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...
0
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
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 ...

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.