Public Function Acos

D

David McKnight

I have the following query:

Distance Traveled:
Acos(((Cos([Location_2.Lat-radians])*Cos([Location.Lat-radians])+Sin([Location_2.Lat-radians])*Sin([Location.Lat-radians]))*Cos(([Location_2.Long-radians])-([Location.Long-radians]))))*3958.756


Since I know Access doesn't have a built in Acos function I have created a
module:


Public Function Acos(X)
Atn (-X / Sqr(-X * X + 1)) + 2 * Atn(1)
End Function

But I still get an error "Undefined function Acos in express" when I try
running the query. What gives?
 
D

Douglas J. Steele

What sort of module did you use for your function? It cannot be a class
module, nor a module associated with a form or report.

Also, how are you trying to use the query? Are you running it from inside of
Access, or are you trying to call it from outside of Access (say, from
Excel)? It will only work if you're using it from within Access.
 
D

David McKnight

Sorry, not sure how to describe what type module. I just went into the module
tab, typed away (actually copied and paste) and saved it as Acos. In boxes
above module design it has "general" & "declarations"

I how do I know if it is a classs module or not?

Query is running inside of Access.
--
David McKnight


Douglas J. Steele said:
What sort of module did you use for your function? It cannot be a class
module, nor a module associated with a form or report.

Also, how are you trying to use the query? Are you running it from inside of
Access, or are you trying to call it from outside of Access (say, from
Excel)? It will only work if you're using it from within Access.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


David McKnight said:
I have the following query:

Distance Traveled:
Acos(((Cos([Location_2.Lat-radians])*Cos([Location.Lat-radians])+Sin([Location_2.Lat-radians])*Sin([Location.Lat-radians]))*Cos(([Location_2.Long-radians])-([Location.Long-radians]))))*3958.756


Since I know Access doesn't have a built in Acos function I have created a
module:


Public Function Acos(X)
Atn (-X / Sqr(-X * X + 1)) + 2 * Atn(1)
End Function

But I still get an error "Undefined function Acos in express" when I try
running the query. What gives?
 
D

Duane Hookom

"and saved it as Acos"... You can't have a module with the same name as your
function. That's one of the reasons why most of us old-timers use naming
conventions.

I generally save modules with names beginning with "bas"
--
Duane Hookom
Microsoft Access MVP


David McKnight said:
Sorry, not sure how to describe what type module. I just went into the module
tab, typed away (actually copied and paste) and saved it as Acos. In boxes
above module design it has "general" & "declarations"

I how do I know if it is a classs module or not?

Query is running inside of Access.
--
David McKnight


Douglas J. Steele said:
What sort of module did you use for your function? It cannot be a class
module, nor a module associated with a form or report.

Also, how are you trying to use the query? Are you running it from inside of
Access, or are you trying to call it from outside of Access (say, from
Excel)? It will only work if you're using it from within Access.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


David McKnight said:
I have the following query:

Distance Traveled:
Acos(((Cos([Location_2.Lat-radians])*Cos([Location.Lat-radians])+Sin([Location_2.Lat-radians])*Sin([Location.Lat-radians]))*Cos(([Location_2.Long-radians])-([Location.Long-radians]))))*3958.756


Since I know Access doesn't have a built in Acos function I have created a
module:


Public Function Acos(X)
Atn (-X / Sqr(-X * X + 1)) + 2 * Atn(1)
End Function

But I still get an error "Undefined function Acos in express" when I try
running the query. What gives?
 
D

David McKnight

That fixed it - thanks
--
David McKnight


Duane Hookom said:
"and saved it as Acos"... You can't have a module with the same name as your
function. That's one of the reasons why most of us old-timers use naming
conventions.

I generally save modules with names beginning with "bas"
--
Duane Hookom
Microsoft Access MVP


David McKnight said:
Sorry, not sure how to describe what type module. I just went into the module
tab, typed away (actually copied and paste) and saved it as Acos. In boxes
above module design it has "general" & "declarations"

I how do I know if it is a classs module or not?

Query is running inside of Access.
--
David McKnight


Douglas J. Steele said:
What sort of module did you use for your function? It cannot be a class
module, nor a module associated with a form or report.

Also, how are you trying to use the query? Are you running it from inside of
Access, or are you trying to call it from outside of Access (say, from
Excel)? It will only work if you're using it from within Access.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)



I have the following query:

Distance Traveled:
Acos(((Cos([Location_2.Lat-radians])*Cos([Location.Lat-radians])+Sin([Location_2.Lat-radians])*Sin([Location.Lat-radians]))*Cos(([Location_2.Long-radians])-([Location.Long-radians]))))*3958.756


Since I know Access doesn't have a built in Acos function I have created a
module:


Public Function Acos(X)
Atn (-X / Sqr(-X * X + 1)) + 2 * Atn(1)
End Function

But I still get an error "Undefined function Acos in express" when I try
running the query. What gives?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top