Date entry mmdd

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My end user wants to be able to enter dates in a date field as 0101 or 010105
and then have it formated as 01/01/05. Can anyone suggest the best way to
achieve this. I get it to work if they always type it the same way but am
having a problem with both scenarios. Thanks, Chris
 
LadyCES said:
My end user wants to be able to enter dates in a date field as 0101 or 010105
and then have it formated as 01/01/05. Can anyone suggest the best way to
achieve this. I get it to work if they always type it the same way but am
having a problem with both scenarios.


There's a lot of potential ambiguity in that request. You'll
have to prevent them from getting any lazier and trying to
enter 101 instead of 0101. Use the text box's AfterUpdate
event:

Private Sub txtDate_AfterUpdate()
Dim strDate As String

strDate = Me.txtDate.Text
Select Case Len(strDate)
Case 4
Me.txtDate = DateSerial(Year(Date), Left(strDate, 2),
Right(strDate, 2))
Case 6
Me.txtDate = DateSerial(Right(strDate, 2),
Left(strDate, 2), Mid(strDate, 2, 2))
Case Else
MsgBox "invalid entry"
End Select

Note that you can not specify anything in the text box's
Format property in this kind of scenario.
 
Thanks Marshall. I had that after update code written but I hoped that there
was either a format or an imput mask that would work. Thanks again. Chris
 
Back
Top