Hi
I am looking for a way to format a date in a textfield troughtout my application. I created a module containing a Function that receive a Date as parameter and returns a string. I put : =formatCustomDate([dbColumnName]) in the source field. Everything works fine when the date is not null. However if the date in the DB is null, empty, etc. The function is not even executed and I get a #Error in the field.
Why is the function not executed? Is there another way to do that? The reason I want to do that is because I want to avoid using the formating embeded in Access. I need the Function to return mm/dd/yyyy (00/00/0000).
Thanks
Jonathan
Here is the code I used to do that:
'*********************************************************
' Function formatCustomDate(dbDate as String) As String
'*********************************************************
Public Function formatCustomDate(dbDate As String) As String
'MsgBox dbDate
On Error GoTo err_Wrong_Date_Type
Dim formatedDate As String
If IsNull(dbDate) Or IsEmpty(dbDate) Or dbDate = CStr("") Then
formatedDate = Empty
Else
formatedDate = Format(dbDate, "mm\/dd\/yyyy")
End If
'MsgBox formatedDate
'MsgBox formatedDate
formatCustomDate = formatedDate
err_Wrong_Date_Type:
If Err.Number <> 0 Then
formatedDate = Empty
formatCustomDate = formatedDate
'MsgBox formatedDate
'MsgBox Err.Number & ":" & Err.Description
Else
formatedDate = Format(dbDate, "mm\/dd\/yyyy")
'MsgBox formatedDate
formatCustomDate = formatedDate
End If
End Function
I am looking for a way to format a date in a textfield troughtout my application. I created a module containing a Function that receive a Date as parameter and returns a string. I put : =formatCustomDate([dbColumnName]) in the source field. Everything works fine when the date is not null. However if the date in the DB is null, empty, etc. The function is not even executed and I get a #Error in the field.
Why is the function not executed? Is there another way to do that? The reason I want to do that is because I want to avoid using the formating embeded in Access. I need the Function to return mm/dd/yyyy (00/00/0000).
Thanks
Jonathan
Here is the code I used to do that:
'*********************************************************
' Function formatCustomDate(dbDate as String) As String
'*********************************************************
Public Function formatCustomDate(dbDate As String) As String
'MsgBox dbDate
On Error GoTo err_Wrong_Date_Type
Dim formatedDate As String
If IsNull(dbDate) Or IsEmpty(dbDate) Or dbDate = CStr("") Then
formatedDate = Empty
Else
formatedDate = Format(dbDate, "mm\/dd\/yyyy")
End If
'MsgBox formatedDate
'MsgBox formatedDate
formatCustomDate = formatedDate
err_Wrong_Date_Type:
If Err.Number <> 0 Then
formatedDate = Empty
formatCustomDate = formatedDate
'MsgBox formatedDate
'MsgBox Err.Number & ":" & Err.Description
Else
formatedDate = Format(dbDate, "mm\/dd\/yyyy")
'MsgBox formatedDate
formatCustomDate = formatedDate
End If
End Function