how to write VB coding using keycode Constants?(for eg. for ESC )

A

Albert D. Kallal

You don't mention if you looking to control keys for a control, or a form
(you can do both)...

however, for example, I have a continues form, and I wanted the arrow keys
to behave like they do in a data sheet.

Further, I wanted the enter key when hit to open up a form to display
additional details.

And, further, for particular customer, the Esc key was to close and save the
form....

So, for most of these custom keystroke type things, you best use the keydown
event. (there are 3 possible events for keystroke processing..).

You *must* set the forms key preview to "yes", and this means that your
forms keydown event can get the key BEFORE the contorls keydown event...

Furhter, since keys like esc, or others that I use will *still* be
proccessed by ms-access, notice how I set the key value = 0, and that throws
the keystock in a balck hole (it will not be seen by contorls).

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

' key hand

Select Case KeyCode

Case vbKeyEscape
KeyCode = 0
DoCmd.Close

Case vbKeyUp
KeyCode = 0
On Error Resume Next
DoCmd.GoToRecord acActiveDataObject, , acPrevious

Case vbKeyDown
KeyCode = 0
On Error Resume Next
DoCmd.GoToRecord acActiveDataObject, , acNext

Case vbKeyReturn
If IsNull(Me.ID) = False Then
KeyCode = 0
Call EditMain
End If

End Select

End Sub

the above should give you an idea how you can re-map, or take over what keys
normally do....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top