UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> NumericDateEntry    

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


Creative Commons License
NumericDateEntry by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 3,325 times.  This page was last modified 21:46, 13 May 2011 by Jack Leach.   Disclaimers