Undefined Function in Expression

G

Guest

I am trying to convert the a date like 20050621 to a numeric format in the
same layout as shown. I made a new function in the data base to do this
converting (see below) but everytime I try an run it in the query I get the
Undefined Function ConvertDatetoNumeric in Expression. Can somebody tell me
what I am doing wrong or what I need to correct this problem. I am on Access
2000 and my operation system is 2000.
Thanks>
Function ConvertDateToNumeric(pDate As Date) As Long

Dim LYear As Integer
Dim LMth As Integer
Dim LDay As Integer

'Extract the year, month, and day values from the date parameter called
pDate
LYear = DatePart("yyyy", pDate)
LMth = DatePart("m", pDate)
LDay = DatePart("d", pDate)

'Format new number as a ddmmyyyy value
ConvertDateToNumeric = Right("00" & CStr(LDay), 2) & Right("00" &
CStr(LMth), 2) & CLng(CStr(LYear))

End Function
 
G

Guest

You are attempting to return a string when the return data type in long

try replacing the last code line with

ConvertDateToNumeric = (LDay * 1000000) + (LMth * 10000) + LYear

or leave the code the way it is, but change the return type to string as in

Function ConvertDateToNumeric(pDate As Date) As string
 
G

Guest

Try this
Function ConvertDateToNumeric(pDate As Date) As Double
If isnull(pDate) then
ConvertDateToNumeric=0
Else
ConvertDateToNumeric = cdbl(Format(pDate , "ddmmyyyy"))
End If
End Function
 
G

Guest

I just wanted to think you for the help. Changing it to a string work.

Thanks for the Help
 

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