|
|
This function takes a purely numeric date entry (ex 051311) and converts it to an Access-recognizable date format (ex 05/13/2011). Use only with the Change event of the control. Data Entry personnel may thank you for it... CODE '========================================================== ' http://www.utteraccess.com/wiki/index.php/NumericDateEntry ' Code courtesy of UtterAccess Wiki ' Licensed under Creative Commons License ' http://creativecommons.org/licenses/by-sa/3.0/ ' ' You are free to use this code in any application, ' provided this notice is left unchanged. ' ' NAME: NumericDateEntry ' DATE: 5/13/2011 ' FOR USE ONLY WITH THE CHANGE EVENT OF A DATE CONTROL! ' Converts a six digit numeric entry to a date recognizable by Access ' ex: 051311 = 05/13/2011 '========================================================== Public Function NumericDateEntry(ByRef ctl As Control) On Error GoTo Error_Proc '========================= Dim s As String '========================= s = Nz(ctl.Text) If (Len(s) = 6) And (IsNumeric(s)) Then ctl.Text = Left(s, 2) & "/" & Mid(s, 3, 2) & "/" & Right(s, 2) End If '========================= Exit_Proc: Exit Function Error_Proc: Select Case Err.Number Case 2113 'invalid entry for the field Err.Clear GoTo Exit_Proc 'exit and let the form handle the error Case Else MsgBox "Error: " & Trim(str(Err.Number)) & vbCrLf & _ "Desc: " & Err.Description & vbCrLf & vbCrLf & _ "Procedure: NumericDateEntry" _ , vbCritical, "Error!" End Select Resume Exit_Proc Resume End Function
|
| This page was last modified 21:46, 13 May 2011. This page has been accessed 372 times. Disclaimers |