Access Modules

T

Tausif Alam

Hi Guru,

I need your help again. I like to call a access Module in access query. But
it gives me error.

Module:
-----------
Function GetDatePart(pDate As Date) As String

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
GetDatePart = Right("00" & CStr(LMth), 2) & "/" & Right("00" &
CStr(LDay), 2) & "/" & CLng(CStr(LYear))
End Function

QUERY:
-----------
SELECT GetDatePart(datestamp) from table1

Please guide me if I am doing any thing wrong.

Tausif.
 
J

John Spencer (MVP)

If DateStamp is a date field, all you need to do is to apply the format to it.

FORMAT(DateStamp,"DD/MM/YYYY")

If DateStamp is not a date field, but a string that you want to formatted as a
date then your code will fail since you are requiring an datetime variable as an
input and a string is NOT a datetime variable.
 

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