I'm venturing (for the first time) into the realm of the KeyDown, KeyPress, KeyUp, etc. domain. I have successfully managed to get it to where it will recognize when I have pressed Ctrl + 1, Ctrl + 2, etc. I just want to make sure that I'm doing it in the way that is best. I had so much trouble figuring out how to do the multi-key testing that I'm just not sure. Here is my code:
I'm only testing for the shift of 3 (the VbCtrlMask + VbShiftMask) as I only need to know if both the Ctrl and Shift keys are pressed at the same time with an additional number or letter. I then am testing for the third key that was pressed (strCharacter). I then test for that value in the Select Case statement to tack onto the end of the text in LegalWording (a textbox on the form).
Again, this does work (surprisingly so since I did it on my own), but I just want to know if this is an acceptable way.
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim ShiftKey As Integer
Dim strCharacter As String
strCharacter = Chr(KeyCode)
ShiftKey = Shift And 7
If ShiftKey = 3 Then
Select Case strCharacter
Case 1 To 9
Call insertBlank(" %Blank" & strCharacter & "% ")
Case "a"
Call insertBlank(" %Accused% ")
Case "o"
Call insertBlank(" %Officer% ")
Case "p"
Call insertBlank(" %PenalCode% ")
End Select
End If
End Sub
Code:
Private Sub insertBlank(strBlank As String)
Dim strWording As String
With Me.LegalWording
.SetFocus
strWording = .Text
strWording = strWording & strBlank
.Value = strWording
.SelStart = Len(.Text)
End With
End Sub
Again, this does work (surprisingly so since I did it on my own), but I just want to know if this is an acceptable way.
Comment