PDA

View Full Version : Access Modules


Tausif Alam
May 24th, 2004, 07:14 AM
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.

John Spencer (MVP)
May 24th, 2004, 08:22 PM
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.



Tausif Alam wrote:
>
> 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.

Google