I am trying to convert an Excel workbook into Access. It is a straight-forward conversion with one exception. I am using some advanced functions in Excel that I can’t load into Access. For instance, Arcatangent…ATAN() in XL and PI() are two that are not available in Access. How can I add Functions to Access? They are available in XL so it seems I should be able to leverage them in Access.
Cheers!
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Access Wksheet Function? (v2000)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Access Wksheet Function? (v2000)
- This topic has 18 replies, 2 voices, and was last updated 20 years, 6 months ago.
AuthorTopicWSdashiell
AskWoody LoungerDecember 1, 2004 at 12:36 am #412930Viewing 3 reply threadsAuthorReplies-
WSHansV
AskWoody LoungerDecember 1, 2004 at 12:47 am #907177You could set a reference to the Excel object library and create an Excel application object in order to be able to use Excel functions, but it is a lot of overhead.
Atn is the general VBA equivalent of ATAN, and Pi can be computed as Pi = Atn(1) * 4.
If you need more functions, check out ACC97: Neatcd97.mdb Available in Download Center. Although designed for Access 97, it is useful in later versions of Access too.
-
WSdashiell
AskWoody Lounger -
WSdashiell
AskWoody Lounger
-
-
WSHansV
AskWoody LoungerDecember 1, 2004 at 12:47 am #907178You could set a reference to the Excel object library and create an Excel application object in order to be able to use Excel functions, but it is a lot of overhead.
Atn is the general VBA equivalent of ATAN, and Pi can be computed as Pi = Atn(1) * 4.
If you need more functions, check out ACC97: Neatcd97.mdb Available in Download Center. Although designed for Access 97, it is useful in later versions of Access too.
-
WSdashiell
AskWoody LoungerDecember 1, 2004 at 12:48 am #907179Ok…I found a way to pull Excel functions via code in: http://support.microsoft.com/default.aspx?…kb;en-us;198571
For instance, if I want to reference the Median() function in Excel, they illustrate the following code:
>>>>>>>>>>>>>>>>
Sub xlMedian()
Dim objExcel As Excel.Application
Set objExcel = CreateObject(“Excel.Application”)
MsgBox objExcel.Application.Median(1, 2, 5, 8, 12, 13)
objExcel.Quit
Set objExcel = Nothing
End Sub
>>>>>>>>>>>>>>>>
However, I need to reference this function in a query. For illustrative sake, I want to find the median of [JohnsSales] and [SuesSales], how would I do this?
Thanks!! -
WSHansV
AskWoody LoungerDecember 1, 2004 at 12:54 am #907181See post 301021 for a median function implemented in Access, with examples of use.
-
WSdashiell
AskWoody LoungerDecember 1, 2004 at 2:04 am #907197Hans,
I worked hard not to bug you but I hit a snag. When I calculate using the GreatArcDistance() function, I have two small issues. What do I use as the radius (I am assuming 6,378.8 kilometers because that is the assumed radius of the earth). Finally, in what units is the final answer? It is too large to be miles or meters. I know you don’t have all the answers but do you know of a document that goes into more details on these calculations?
Thanks!
Dashiell -
WSHansV
AskWoody LoungerDecember 1, 2004 at 8:24 am #907221I hadn’t studied the sample database closely. It seems to be buggy: both the ArcCos and GreatArcDistance functions are incorrect. Here are hopefully correct versions (you still need other functions from the sample database:
Function ArcCos(x As Double) As Double
‘ Inverse Cosine
If x = 1 Then
ArcCos = 0
ElseIf x = -1 Then
ArcCos = Pi
Else
ArcCos = Pi / 2 – Atn(x / Sqr(-x * x + 1))
End If
End FunctionFunction GreatArcDistance(Lat1 As Double, Lon1 As Double, Lat2 As Double, Lon2 As Double, Radius As Double) As Double
‘ Calculates the Great Arc (shortest) distance between 2 locations on the globe.
‘ Uses functions from Trigonometry
Dim X1 As Double
Dim Y1 As Double
Dim Z1 As Double
Dim X2 As Double
Dim Y2 As Double
Dim Z2 As Double
Dim CosX As Double
Dim ChordLen As Double
LatLongToXYZ Lat1, Lon1, Radius, X1, Y1, Z1
LatLongToXYZ Lat2, Lon2, Radius, X2, Y2, Z2
ChordLen = Sqr((X1 – X2) * (X1 – X2) + (Y1 – Y2) * (Y1 – Y2) + (Z1 – Z2) * (Z1 – Z2))
CosX = 1 – ChordLen * ChordLen / (2 * Radius * Radius)
GreatArcDistance = ArcCos(CosX) * Radius
End Function -
WSdashiell
AskWoody LoungerDecember 1, 2004 at 1:51 pm #907295Hans,
That gets me much closer. Here are the zip codes I’m using as tests as well as their XY coordinates:Zip1 Lat1 Lon1 Zip2 Lat2 Lon2 GreatArcAnswer
48072 42.498463 -83.185364 48111 42.18206 -83.485329 43.013401991036The calculation I am using in the query is as follows:
GreatArcAnswer: GreatArcDistance([Lat1],[Lon1],[Lat2],[Lon2],6378.8)where 6378.8 is the earth’s approximate radius in kilometers. The answer should be closer to 26 miles but the answer is coming up as 43.0134. I’m not certain if the radius is correct or what the 43.0134 actually represents. If you have any more insight, I would appreciate it. Please don’t spend any more time on it if you don’t know straight away.
Thanks!
Andrew -
WSHansV
AskWoody Lounger -
WSdashiell
AskWoody Lounger -
WSdashiell
AskWoody Lounger -
WSHansV
AskWoody Lounger -
WSdashiell
AskWoody LoungerDecember 1, 2004 at 1:51 pm #907296Hans,
That gets me much closer. Here are the zip codes I’m using as tests as well as their XY coordinates:Zip1 Lat1 Lon1 Zip2 Lat2 Lon2 GreatArcAnswer
48072 42.498463 -83.185364 48111 42.18206 -83.485329 43.013401991036The calculation I am using in the query is as follows:
GreatArcAnswer: GreatArcDistance([Lat1],[Lon1],[Lat2],[Lon2],6378.8)where 6378.8 is the earth’s approximate radius in kilometers. The answer should be closer to 26 miles but the answer is coming up as 43.0134. I’m not certain if the radius is correct or what the 43.0134 actually represents. If you have any more insight, I would appreciate it. Please don’t spend any more time on it if you don’t know straight away.
Thanks!
Andrew
-
-
WSHansV
AskWoody LoungerDecember 1, 2004 at 8:24 am #907222I hadn’t studied the sample database closely. It seems to be buggy: both the ArcCos and GreatArcDistance functions are incorrect. Here are hopefully correct versions (you still need other functions from the sample database:
Function ArcCos(x As Double) As Double
‘ Inverse Cosine
If x = 1 Then
ArcCos = 0
ElseIf x = -1 Then
ArcCos = Pi
Else
ArcCos = Pi / 2 – Atn(x / Sqr(-x * x + 1))
End If
End FunctionFunction GreatArcDistance(Lat1 As Double, Lon1 As Double, Lat2 As Double, Lon2 As Double, Radius As Double) As Double
‘ Calculates the Great Arc (shortest) distance between 2 locations on the globe.
‘ Uses functions from Trigonometry
Dim X1 As Double
Dim Y1 As Double
Dim Z1 As Double
Dim X2 As Double
Dim Y2 As Double
Dim Z2 As Double
Dim CosX As Double
Dim ChordLen As Double
LatLongToXYZ Lat1, Lon1, Radius, X1, Y1, Z1
LatLongToXYZ Lat2, Lon2, Radius, X2, Y2, Z2
ChordLen = Sqr((X1 – X2) * (X1 – X2) + (Y1 – Y2) * (Y1 – Y2) + (Z1 – Z2) * (Z1 – Z2))
CosX = 1 – ChordLen * ChordLen / (2 * Radius * Radius)
GreatArcDistance = ArcCos(CosX) * Radius
End Function
-
-
WSdashiell
AskWoody LoungerDecember 1, 2004 at 2:04 am #907198Hans,
I worked hard not to bug you but I hit a snag. When I calculate using the GreatArcDistance() function, I have two small issues. What do I use as the radius (I am assuming 6,378.8 kilometers because that is the assumed radius of the earth). Finally, in what units is the final answer? It is too large to be miles or meters. I know you don’t have all the answers but do you know of a document that goes into more details on these calculations?
Thanks!
Dashiell
-
-
WSHansV
AskWoody LoungerDecember 1, 2004 at 12:54 am #907182See post 301021 for a median function implemented in Access, with examples of use.
-
-
WSdashiell
AskWoody LoungerDecember 1, 2004 at 12:48 am #907180Ok…I found a way to pull Excel functions via code in: http://support.microsoft.com/default.aspx?…kb;en-us;198571
For instance, if I want to reference the Median() function in Excel, they illustrate the following code:
>>>>>>>>>>>>>>>>
Sub xlMedian()
Dim objExcel As Excel.Application
Set objExcel = CreateObject(“Excel.Application”)
MsgBox objExcel.Application.Median(1, 2, 5, 8, 12, 13)
objExcel.Quit
Set objExcel = Nothing
End Sub
>>>>>>>>>>>>>>>>
However, I need to reference this function in a query. For illustrative sake, I want to find the median of [JohnsSales] and [SuesSales], how would I do this?
Thanks!!
Viewing 3 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Search Forums only bring up my posts?
by
Deo
5 minutes ago -
Windows Spotlight broken on Enterprise and Pro for Workstations?
by
steeviebops
7 hours, 54 minutes ago -
Denmark wants to dump Microsoft for Linux + LibreOffice
by
Alex5723
31 minutes ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
8 hours, 31 minutes ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
18 hours, 39 minutes ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
19 hours, 45 minutes ago -
Disengage Bitlocker
by
CWBillow
9 hours, 43 minutes ago -
Mac Mini M2 Service Program for No Power Issue
by
Alex5723
21 hours, 45 minutes ago -
New Win 11 Pro Geekom Setup questions
by
Deo
1 hour, 31 minutes ago -
Windows 11 Insider Preview build 26200.5651 released to DEV
by
joep517
1 day, 5 hours ago -
Windows 11 Insider Preview build 26120.4441 (24H2) released to BETA
by
joep517
1 day, 5 hours ago -
iOS 26,, MacOS 26 : Create your own AI chatbot
by
Alex5723
1 day, 8 hours ago -
New PC transfer program recommendations?
by
DaveBoston
4 hours, 19 minutes ago -
Windows 11 Insider Preview Build 22631.5545 (23H2) released to Release Preview
by
joep517
1 day, 13 hours ago -
Windows 10 Build 19045.6029 (22H2) to Release Preview Channel
by
joep517
1 day, 13 hours ago -
Best tools for upgrading a Windows 10 to an 11
by
Susan Bradley
1 day, 1 hour ago -
The end of Windows 10 is approaching, consider Linux and LibreOffice
by
Alex5723
5 hours, 25 minutes ago -
Extended Windows Built-in Disk Cleanup Utility
by
bbearren
14 hours, 19 minutes ago -
Win 11 24H2 June 2025 Update breaks WIFI
by
dportenlanger
2 days, 8 hours ago -
Update from WinPro 10 v. 1511 on T460p?
by
CatoRenasci
1 day, 5 hours ago -
System Restore and Updates Paused
by
veteran
2 days, 10 hours ago -
Windows 10/11 clock app
by
Kathy Stevens
1 day, 21 hours ago -
Turn off right-click draw
by
Charles Billow
2 days, 13 hours ago -
Introducing ChromeOS M137 to The Stable Channel
by
Alex5723
2 days, 17 hours ago -
Brian Wilson (The Beach Boys) R.I.P
by
Alex5723
1 hour, 54 minutes ago -
Master patch listing for June 10, 2025
by
Susan Bradley
2 days, 18 hours ago -
Suggestions for New All in One Printer and a Photo Printer Windows 10
by
Win7and10
1 hour, 36 minutes ago -
Purchasing New Printer. Uninstall old Printer Software First?
by
Win7and10
3 days ago -
KB5060842 Issue (Minor)
by
AC641
1 day, 13 hours ago -
EchoLeak : Zero Click M365 Copilot leak sensitive information
by
Alex5723
3 days, 8 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.