How to do the trig function Arc Cos (ACOS() in Exc

2019-07-21 06:03发布

I have an excel formula that I need to put into an MS-Access query. Unfortunately, an Arc Cosine function does not seem to be part of Access's repertoire. So in Excel, part of the formula is ACOS(Lots of stuff). So my question is how can I achieve an ACOS() Excelfunction in MS-Access?

Note: In case anyone is wondering or in case it actually matters for some odd reason, here is the full equation as it appears in Excel:

=(ACOS(SIN(RADIANS(AX2))*SIN(RADIANS(AZ2))+COS(RADIANS(AX2))*COS(RADIANS(AZ2))*COS(RADIANS(AY2)-RADIANS(BA2)))*6367)*0.621

Columns AX and AZ hold latitudes and AY and BA hold longitudes and this equation gets the distance in miles between the two points. And before anyone brings it up I am aware that Access doesn't have Radians function. I have already replaced it with an equivalent operation. I of course have changed the column references from Excel to the appropriate Access field references.

1条回答
女痞
2楼-- · 2019-07-21 06:31

I have found two ways to do this. The first, and the one I used, is to use an equivalent trig identity for the ACOS() function:

Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)

This results in a rather long equation for me but it works and does not appear take very long to run. The other solution I have read about (but not tested) is to create a

reference to the Microsoft Excel Object Library (Tools | References on the VBA menu bar). This exposes the Excel worksheet functions, which you can reference with:

Excel.WorksheetFunction.ACOS(TheNumberGoesHere)

查看更多
登录 后发表回答