Date fast entry

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

Guest

is it possible to enter a two digit number ( in a feild on a form), and run a procedure that will display the two digit number as the day value in short date format. The month and year would come from the current computer date value. ie.. I enter 02 the display value= 04/02/04. Next problem, if I enter 0502 the display value should be = 05/02/04.
thanks for helpin
Alex
 
Alex said:
is it possible to enter a two digit number ( in a feild on a form), and
run a procedure that will display the two digit number as the day value in
short date format. The month and year would come from the current computer
date value. ie.. I enter 02 the display value= 04/02/04. Next problem, if I
enter 0502 the display value should be = 05/02/04.

Sure, you'll need to write a little code in the control's after update
event. Here's some untested (aircode) that might do it for you. Watch out
for line wrap:

Sub txtMyDate_AfterUpdate()
Select Case Len(Me.txtMyDate)
Case 2
Me.txtMyDate = Format(Month(Date) & "/" & Me.txtMyDate & "/" &
Year(Date), "mm/dd/yy")
Case 4
Me.txtMyDate = Format(Left(Me.txtMyDate,2) & "/" &
Right(Me.txtMyDate,2) & "/" & Year(Date), "mm/dd/yy")
Case 6
Me.txtMyDate = Format(Left(Me.txtMyDate,2) & "/"
Mid(Me.txtMyDate,2,2) & "/" & Right(Me.txtMyDate,2), "mm/dd/yy")
Case Else
MsgBox "Invalid Entry", vbOKOnly, "Wake Up!"
End Select
End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
This works great if the field is unbound. My problem now is that the field is bound with a data type "Date/Time", format "Short Date". I use the date value to do date calculations elsewhere. It seems that Access looks at the value enter and validates it to "Data Type" before executing the After Update. Any ideas??
 
Alex said:
This works great if the field is unbound. My problem now is that the field
is bound with a data type "Date/Time", format "Short Date". I use the date
value to do date calculations elsewhere. It seems that Access looks at the
value enter and validates it to "Data Type" before executing the After
Update. Any ideas??

Sure use the code in an unbound textbox, then write to a bound control by
adding a line like:

Me.txtBoundControl = Me.txtMyDate

in a line just before the End Sub or exit routine.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Same idea I had, but.... I'm using a datasheet view and when you change the unbound it changes all lines of data for that field. I think I could make something work with a major design change (single line continuous form, that looks like a datasheet ???) Any other ideas would be appreciated
Thanks Alex
 
Back
Top