I have tried to use this function to convert my date from a string to a
date
and am having trouble. I keep receiving a conversion error when I run my
function. I am relatively new to Access programming, so I am sure I have
just missed something in my code, so if anyone is willing to help me out
it
would be great. I am trying to convert a string in one table that is in
yymmdd format to a date in another table using dd/mm/yy format. The
following is the function I have come up with so far.
Public Function ConvertDate()
On Error GoTo ConvertDate_Err
Dim datein As String
Dim date1 As String
Dim date2 As String
Dim date3 As String
Dim dateout As String
datein = DLookup("[date]", "[tbleraw]")
date1 = Left("datein", 2)
date2 = Mid("datein", 2, 2)
date3 = Mid("datein", 4, 2)
dateout = date3 & date2 & date1
DLookup("[date]", "[tblenldb]") = CDate(dateout)
ConvertDate_Exit:
Exit Function
ConvertDate_Err:
MsgBox "Error " & Err & " : " & Err.Description
GoTo ConvertDate_Exit
End Function
If anyone can tell me what I am doing wrong, I would appreciate it.
Allen Browne said:
To convert a string representation of a date into a date/time value, use
CDate().
If the comparison involves literal dates in a SQL string, be sure to
format
mm/dd/yyyy, and include the # delimiters.