Has anyone ever tried populating a date field on a form when a certain key is pressed. For example, if I press "t", then it puts in today's date.
I have a way to do it, but I don't like it and I'm looking for advice to better this.
Here is the code the form field calls:
Here is the public function in my module:
It would be nice to have this apply to all controls that have a date format, but that's beyond me.
I also have to watch out for only certain keys. That's why in the key up event I'm watching for null and that #12:00:00 AM# value. If I don't have that statement, any other key press will return back 12/30/1899.
Any advice or input would be fantastic!
Thanks!
I have a way to do it, but I don't like it and I'm looking for advice to better this.
Here is the code the form field calls:
Code:
Private Sub ProgramStartDate_KeyUp(KeyCode As Integer, Shift As Integer)
If IsNull(GetHotDate(KeyCode)) Or GetHotDate(KeyCode) = #12:00:00 AM# Then
Exit Sub
Else
Me.ProgramStartDate = GetHotDate(KeyCode)
End If
End Sub
Code:
Public Function GetHotDate(intK As Integer) As Date
Select Case intK
Case 84
'todays date
GetHotDate = Date
Case 89
'yesterdays date
GetHotDate = Date - 1
Case 87
'tomorrows date
GetHotDate = Date + 1
End Select
End Function
It would be nice to have this apply to all controls that have a date format, but that's beyond me.
I also have to watch out for only certain keys. That's why in the key up event I'm watching for null and that #12:00:00 AM# value. If I don't have that statement, any other key press will return back 12/30/1899.
Any advice or input would be fantastic!
Thanks!