Hi There,
I am trying to clean up repetitive code in an application I wrote many years ago. So far this process has been working well for reducing repetitive code volume and making the application easier to maintain.
But I am having trouble with the attached Subroutines that I would like to consolidate/simplify..
Note that I am working on data entry forms. Most date input fields have a default value set to 'Date()'
Simply put if I have a date field and when I enter a Period (.) it inserts todays date. I can increment date by pressing the plus (+) key or decrement date field by using a minus (-) key. This action is triggered by the "OnKeyPress" event which is looking at the value of the Ascii key pressed. See examples below for 'OrderDate' field and' PromisedByDate' field
EDITED BY THE_DOC_MAN: ADDED CODE TAGS, INDENTED THE CODE TO BE READABLE. NO OTHER CHANGES.
So how do I create a simple function that I can call when a Plus, Minus, Period or Equals key is pressed on nominated date fields at key press time?
Thanks in advance
I am trying to clean up repetitive code in an application I wrote many years ago. So far this process has been working well for reducing repetitive code volume and making the application easier to maintain.
But I am having trouble with the attached Subroutines that I would like to consolidate/simplify..
Note that I am working on data entry forms. Most date input fields have a default value set to 'Date()'
Simply put if I have a date field and when I enter a Period (.) it inserts todays date. I can increment date by pressing the plus (+) key or decrement date field by using a minus (-) key. This action is triggered by the "OnKeyPress" event which is looking at the value of the Ascii key pressed. See examples below for 'OrderDate' field and' PromisedByDate' field
EDITED BY THE_DOC_MAN: ADDED CODE TAGS, INDENTED THE CODE TO BE READABLE. NO OTHER CHANGES.
Code:
Private Sub OrderDate_KeyPress(KeyAscii As Integer)
'Toggle date up & Down using + & - Keys
Select Case KeyAscii
Case 61 ' Equals key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl + 1
Case 43 ' Plus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl + 1
Case 45 ' Minus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl - 1
Case 46 'Period Key
KeyAscii = 0
OrderDate = Date
End Select
End Sub
Private Sub PromisedByDate_KeyPress(KeyAscii As Integer)
'Toggle date up & Down using + & - Keys
Select Case KeyAscii
Case 61 ' Equals key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl + 1
Case 43 ' Plus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl + 1
Case 45 ' Minus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl - 1
Case 46 'Period Key
KeyAscii = 0
OrderDate = Date
End Select
End Sub
Thanks in advance
Last edited by a moderator: