473,326 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,326 developers and data experts.

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 18702

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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.