SQRT and ATAN2 functions to MS Access 2007

O

Osama S. Arisheh

Hello there,


any one knows how to add-in or improt SQRT and ATAN2 functions to MS Access
2007?

iam trying to build expression in the Ms access Queries but it fail coz no
SQRT\ATAN2?

Exmple: x:
0.000001*(2*565*atan2(SQRT((2*118.5/[FT1-CM])-1),1)*118.5*118.5+(0.84*PI()*(3*118.5-[FT1-CM])*[FT1-CM]*[FT1-CM])/3+565*SQRT((2*118.5-[FT1-CM])*[FT1-CM])*([FT1-CM]-118.5))
 
B

Brendan Reynolds

Osama S. Arisheh said:
Hello there,


any one knows how to add-in or improt SQRT and ATAN2 functions to MS
Access
2007?

iam trying to build expression in the Ms access Queries but it fail coz no
SQRT\ATAN2?

Exmple: x:
0.000001*(2*565*atan2(SQRT((2*118.5/[FT1-CM])-1),1)*118.5*118.5+(0.84*PI()*(3*118.5-[FT1-CM])*[FT1-CM]*[FT1-CM])/3+565*SQRT((2*118.5-[FT1-CM])*[FT1-CM])*([FT1-CM]-118.5))


VBA has a square root function, the Sqr() function. Here's a link to the
on-line help topic ...

http://office.microsoft.com/client/helppreview.aspx?AssetID=HV012041671033&ns=MSACCESS.DEV

There's an example of a VBA Atan2 function at the following URL ...

http://en.wikibooks.org/wiki/Progra...c/Simple_Arithmetic#Trigonometrical_Functions
 
O

Osama S. Arisheh

Brendan Reynolds said:
Osama S. Arisheh said:
Hello there,


any one knows how to add-in or improt SQRT and ATAN2 functions to MS
Access
2007?

iam trying to build expression in the Ms access Queries but it fail coz no
SQRT\ATAN2?

Exmple: x:
0.000001*(2*565*atan2(SQRT((2*118.5/[FT1-CM])-1),1)*118.5*118.5+(0.84*PI()*(3*118.5-[FT1-CM])*[FT1-CM]*[FT1-CM])/3+565*SQRT((2*118.5-[FT1-CM])*[FT1-CM])*([FT1-CM]-118.5))


VBA has a square root function, the Sqr() function. Here's a link to the
on-line help topic ...

http://office.microsoft.com/client/helppreview.aspx?AssetID=HV012041671033&ns=MSACCESS.DEV

There's an example of a VBA Atan2 function at the following URL ...

http://en.wikibooks.org/wiki/Progra...c/Simple_Arithmetic#Trigonometrical_Functions

Thank you Brendan.

i know how to do it by vb code but its working from queries? any way still I
am not able to find ATAN2 ? i have got it as function, but when Iam calling
it from Queries its not working?

Option Compare Database

Function atan2(ys, xs)
' Given y and x coords returns atan2
' by Jim Deutch, Syracuse, New York
Dim theta, pi
pi = 3.14159265358979
If xs <> 0 Then
theta = Atn(ys / xs)
If xs < 0 Then
theta = theta + pi
End If
Else
If ys < 0 Then
theta = 3 * pi / 2 '90
Else
theta = pi / 2 '270
End If
End If
atan2 = theta
End Function
 
B

Brendan Reynolds

message
i know how to do it by vb code but its working from queries? any way still
I
am not able to find ATAN2 ? i have got it as function, but when Iam
calling
it from Queries its not working?

Option Compare Database

Function atan2(ys, xs)
' Given y and x coords returns atan2
' by Jim Deutch, Syracuse, New York
Dim theta, pi
pi = 3.14159265358979
If xs <> 0 Then
theta = Atn(ys / xs)
If xs < 0 Then
theta = theta + pi
End If
Else
If ys < 0 Then
theta = 3 * pi / 2 '90
Else
theta = pi / 2 '270
End If
End If
atan2 = theta
End Function

First make sure the function is public, not private. If I remember rightly
(and I am going from memory here so I could be wrong) I think when you dont'
specify public or private, the function is public by default if declared in
a standard module but private by default if declared in a class module such
as a form or report module. So make sure your function is in a standard
module. Its probably good practice to explicitly declare it as public any
way ...

Public Function atan2(ys, xs)

... and please, please, please use Option Explict, not using it is a
guaranteed way to cause endless problems for yourself and anyone else who
has to deal with your code ...

Option Compare Database
Option Explicit

Public Function atan2(ys, xs)

If the function is public, you shouldn't have any difficulty calling it from
a query. If you're sure it's public and you still can't call it from a
query, someone will probably be able to tell you what the problem is if you
post the SQL.
 
O

Osama S. Arisheh

Brendan Reynolds said:
message

First make sure the function is public, not private. If I remember rightly
(and I am going from memory here so I could be wrong) I think when you dont'
specify public or private, the function is public by default if declared in
a standard module but private by default if declared in a class module such
as a form or report module. So make sure your function is in a standard
module. Its probably good practice to explicitly declare it as public any
way ...

Public Function atan2(ys, xs)

... and please, please, please use Option Explict, not using it is a
guaranteed way to cause endless problems for yourself and anyone else who
has to deal with your code ...

Option Compare Database
Option Explicit

Public Function atan2(ys, xs)

If the function is public, you shouldn't have any difficulty calling it from
a query. If you're sure it's public and you still can't call it from a
query, someone will probably be able to tell you what the problem is if you
post the SQL.


thank you very much Brendan for reply.

i just add it the "Option Compare Database" and "Option Explicit" and "
Public Function atan2(ys, xs)" in Access VBA and in the same form too but it
still not calling it?

the SQL:
SELECT Calculation.SN, Calculation.Date, Calculation.Start, Calculation.End,
Calculation.TotalTime, Calculation.TotalTime_HR, Calculation.[FT1-CM],
Calculation.[FT'], Calculation.[FT"], Calculation.[FT2-CM],
Calculation.[PT1-CM], Calculation.[PT'], Calculation.[PT"],
Calculation.[PT2-CM], [Calculation]![Start]-[Calculation]![End] AS
WFTOpening,
0.000001*(2*565*atan2(Sqr((2*118.5/[FT1-CM])-1),1)*118.5*118.5+(0.84*PI()*(3*118.5-[FT1-CM])*[FT1-CM]*[FT1-CM])/3+565*SQRT((2*118.5-[FT1-CM])*[FT1-CM])*([FT1-CM]-118.5)) AS Test
FROM Calculation;
 
D

Douglas J. Steele

To be usable in a query, the function needs to be in a stand-alone module,
not a module associated with a form.

As well, be aware that the query cannot be called from outside of Access
(i.e.: you won't be able to use the query from, say, Excel)
 
O

Osama S. Arisheh

thank you Douglas, thank you man.
its work i dont know how i miss that, but it ask about PI() function... i
will work on it


Douglas J. Steele said:
To be usable in a query, the function needs to be in a stand-alone module,
not a module associated with a form.

As well, be aware that the query cannot be called from outside of Access
(i.e.: you won't be able to use the query from, say, Excel)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Osama S. Arisheh said:
i just add it the "Option Compare Database" and "Option Explicit" and "
Public Function atan2(ys, xs)" in Access VBA and in the same form too but
it
still not calling it?

the SQL:
SELECT Calculation.SN, Calculation.Date, Calculation.Start,
Calculation.End,
Calculation.TotalTime, Calculation.TotalTime_HR, Calculation.[FT1-CM],
Calculation.[FT'], Calculation.[FT"], Calculation.[FT2-CM],
Calculation.[PT1-CM], Calculation.[PT'], Calculation.[PT"],
Calculation.[PT2-CM], [Calculation]![Start]-[Calculation]![End] AS
WFTOpening,
0.000001*(2*565*atan2(Sqr((2*118.5/[FT1-CM])-1),1)*118.5*118.5+(0.84*PI()*(3*118.5-[FT1-CM])*[FT1-CM]*[FT1-CM])/3+565*SQRT((2*118.5-[FT1-CM])*[FT1-CM])*([FT1-CM]-118.5))
AS Test
FROM Calculation;
 

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