One very handy feature to have is the ability to imitate Quicken or Microsoft Money in the ability to press + or - to increase or decrease the values in a certain field. You can use it, for example, to make "A" increase to "B" and then "C", or to decrease when you hit the - key. Another good example is to use for date fields to make the values, as mentioned, in a Quicken or Microsoft Money manner, by having the date scroll forward or backward by using the + or - keys.
To do this, you use Visual Basic coding within the "On Key Press" event. You would also utilize CHR codes, which can be accessed under Access 97 "help" using the "character set" topic.
Following are some examples:
Assuming the name of the date field is "date_1," the following code would be applied to the "On Key Press" event of the "date_1" text box:
Private Sub date_1_KeyPress(KeyAscii As Integer) Dim xyz As Date If KeyAscii = 43 Then xyz = Me.date_1 xyz = xyz + 1 KeyAscii = 0 Me.date_1 = xyz End If If KeyAscii = 45 Then xyz = Me.date_1 xyz = xyz - 1 Me.date_1 = xyz KeyAscii = 0 End If End Sub |
Assuming you have a text box named "visual," which normally has "A" or "B" etc in its box, and you want to be able to easily scroll the list using the + or - keys, the following code---applied to the "On Key Press" event of the text box--would do it:
Private Sub visual_KeyPress(KeyAscii As Integer) Dim xyz As String, xy As Integer If KeyAscii = 43 Then xyz = Me.visual xy = Asc(xyz) xy = xy + 1 xyz = Chr(xy) Me.visual = xyz KeyAscii = 0 End If If KeyAscii = 45 Then xyz = Me.visual xy = Asc(xyz) xy = xy - 1 xyz = Chr(xy) Me.visual = xyz KeyAscii = 0 End If End Sub |
What this coding does is allows the user the use the numeric keypad--with NUMLOCK on, on top of that--to "pop-up" the combo-box on a form and then scroll through the options--all from the numeric keypad (again with NUMLOCK ON). I find this to be especially handy when a data-entry clerk is mainly entering numeric values with the exception of a combo-box or two. This prevents them from having to remove their hand from the numeric keypad just for those 1 or 2 combo boxes, allowing them to stay in place for high-speed numeric data-entry for the other fields.
With this code, the "8" key--which doubles as the "up-arrow" key if NUMLOCK is OFF--will function as the "up-arrow" key, with NUMLOCK still left ON. Conversely for the "2" key, which doubles as a "down-arrow" key if NUMLOCK is OFF. The user can use this as a "down-arrow" key with NUMLOCK still left ON. The "5" key--in-between these 2 days--is the key used for popping open (or closing) the combo-box to allow the scrolling in the 1st place. Finally, the user, will press ENTER to finalize their choice & go to the next field.
To do this, apply the following code to the "On Key Press" event of the text box. The code here DOES NOT have to be altered depending on the name of the text box.
Private Sub id_sd_KeyPress(KeyAscii As Integer) '53 is the ASCII equivalent of the 5 key If KeyAscii = 53 Then SendKeys "{F4}" KeyAscii = 0 End If '50 is the 2 character, which on the numeric keypad is like the down-arrow if NUMLOCK is OFF If KeyAscii = 50 Then SendKeys "{down}" KeyAscii = 0 End If If KeyAscii = 56 Then SendKeys "{up}" KeyAscii = 0 End If End Sub |