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, 5 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
-
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
2 hours, 55 minutes ago -
False error message from eMClient
by
WSSebastian42
7 hours, 34 minutes ago -
Awoke to a rebooted Mac (crashed?)
by
rebop2020
5 hours, 50 minutes ago -
Office 2021 Perpetual for Mac
by
rebop2020
7 hours, 3 minutes ago -
AutoSave is for Microsoft, not for you
by
Will Fastie
1 hour, 39 minutes ago -
Difface : Reconstruction of 3D Human Facial Images from DNA Sequence
by
Alex5723
10 hours, 34 minutes ago -
Seven things we learned from WhatsApp vs. NSO Group spyware lawsuit
by
Alex5723
10 hours, 57 minutes ago -
Outdated Laptop
by
jdamkeene
16 hours ago -
Updating Keepass2Android
by
CBFPD-Chief115
21 hours, 25 minutes ago -
Another big Microsoft layoff
by
Charlie
21 hours, 5 minutes ago -
PowerShell to detect NPU – Testers Needed
by
RetiredGeek
30 minutes ago -
May 2025 updates are out
by
Susan Bradley
1 hour, 27 minutes ago -
Windows 11 Insider Preview build 26200.5600 released to DEV
by
joep517
1 day, 3 hours ago -
Windows 11 Insider Preview build 26120.3964 (24H2) released to BETA
by
joep517
1 day, 3 hours ago -
Drivers suggested via Windows Update
by
Tex265
1 day, 3 hours ago -
Thunderbird release notes for 128 esr have disappeared
by
EricB
1 day ago -
CISA mutes own website, shifts routine cyber alerts to X, RSS, email
by
Nibbled To Death By Ducks
1 day, 10 hours ago -
Apple releases 18.5
by
Susan Bradley
1 day, 4 hours ago -
Fedora Linux 40 will go end of life for updates and support on 2025-05-13.
by
Alex5723
1 day, 11 hours ago -
How a new type of AI is helping police skirt facial recognition bans
by
Alex5723
1 day, 12 hours ago -
Windows 7 ISO /Windows 10 ISO
by
ECWS
19 hours, 21 minutes ago -
No HP software folders
by
fpefpe
1 day, 19 hours ago -
Which antivirus apps and VPNs are the most secure in 2025?
by
B. Livingston
17 hours, 5 minutes ago -
Stay connected anywhere
by
Peter Deegan
2 days, 1 hour ago -
Copilot, under the table
by
Will Fastie
3 hours, 34 minutes ago -
The Windows experience
by
Will Fastie
2 days, 7 hours ago -
A tale of two operating systems
by
Susan Bradley
11 hours, 36 minutes ago -
Microsoft : Resolving Blue Screen errors in Windows
by
Alex5723
2 days, 12 hours ago -
Where’s the cache today?
by
Up2you2
3 days, 4 hours ago -
Ascension says recent data breach affects over 430,000 patients
by
Nibbled To Death By Ducks
2 days, 20 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.