vb.NET Keypresses

  • Thread starter Thread starter Ian Henderson
  • Start date Start date
I

Ian Henderson

I am currently trying to teach myself .NET (specifically vb.NET). I have
been working with VBA in Access 97 for a few years now, and consider myself
to be quite proficient.

At present, I have an issue with the concept of detecting keypresses. I use
this frequently in Access 97, generally for giving the user an
keyboard-based alternative to clicking on command buttons.

For example, if I have a form where the user will be entering records, as
well as navigating through them, the user has the choice of either clicking
on the various command buttons for navigation and record saving, or pressing
the PgUp and PgDn keys for forward and backward navigation respectively, as
well as the F2 key to save a record. If the user presses CTRL-PgUp/Dn, they
will be able to move to the first or last record in the recordset.

I want to be able to provide this functionality in vb.NET, but can't seem to
find a way of doing it.

I've attached a sample of the code that I would generally use on an Access
form, which I hope will explain what I mean:

Thanks In Advance


Ian Henderson
Database Developer and .NET novice

Private Sub Form_KeyDown(Keycode As Integer, Shift As Integer)

intShiftDown = (Shift And acShiftMask) > 0
intCtrlDown = (Shift And acCtrlMask) > 0
intAltDown = (Shift And acAltMask) > 0

If intShiftDown Then
intShiftDown = 0
Keycode = 0
Exit Sub
End If

If intAltDown Then
intAltDown = 0
Keycode = 0
Exit Sub
End If

If intCtrlDown Then
Select Case Keycode
Case vbKeyQ
strMsg = "Are you sure you wish to quit the " &
DLookup("ShortName", "DatabaseName") & "?"
StrTitle = "Confirm Action"
IntStyle = vbYesNo + vbDefaultButton2
Response = MsgBox(strMsg, IntStyle, StrTitle)
If Response = vbYes Then DoCmd.Quit acQuitPrompt
Keycode = 0
Exit Sub
Case Else
Keycode = 0
Exit Sub
End Select
intCtrlDown = 0
Keycode = 0
Exit Sub
Else
Select Case Keycode
Case vbKeyW
WorkForms.Visible = True
Keycode = 0
Exit Sub
Case vbKeyL
LookupTables.Visible = True
Keycode = 0
Exit Sub
Case vbKeyR
Reports.Visible = True
Keycode = 0
Exit Sub
Case vbKey1
WorkOnBankAccountsBtn_Click
Keycode = 0
Exit Sub
Case vbKey2
WorkOnTelephoneAccountsBtn_Click
Keycode = 0
Exit Sub
Case Else
Keycode = 0
Exit Sub
End Select
End If

End Sub
 
Hello,

Ian Henderson said:
keyboard-based alternative to clicking on command
buttons. [...]
the PgUp and PgDn keys for forward and backward
navigation respectively, as well as the F2 key to save
a record. If the user presses CTRL-PgUp/Dn, they
will be able to move to the first or last record in the recordset.

I want to be able to provide this functionality in vb.NET, but can't seem to
find a way of doing it.

Add a hidden menu and define the shortcuts in the 'MenuItem's'
'Shortcut' property. Then you can add the code to the menu item's
'Click' event handler.
 
Ok, thanks for that.

Having answered that for me, can you tell me how I set the shortcut up to be
the PgUp key, or a combination of SHIFT and PgUp?

Ian

Herfried K. Wagner said:
Hello,

Ian Henderson said:
keyboard-based alternative to clicking on command
buttons. [...]
the PgUp and PgDn keys for forward and backward
navigation respectively, as well as the F2 key to save
a record. If the user presses CTRL-PgUp/Dn, they
will be able to move to the first or last record in the recordset.

I want to be able to provide this functionality in vb.NET, but can't seem to
find a way of doing it.

Add a hidden menu and define the shortcuts in the 'MenuItem's'
'Shortcut' property. Then you can add the code to the menu item's
'Click' event handler.
 
Back
Top