Substitute for Keypress in a Form??

Mgomp

Registered User.
Local time
Today, 20:09
Joined
May 1, 2009
Messages
40
Hi all.

Access 2010 with the navigation forms in use.

On all textboxes I have the Keypressed event.
But what I want, is a routine for the wole form. E.g.: When a form opens, and a user press Alt-R, then a contol.visible = true. If not, it stays unvisible.

How do I trap this for a whole form? KeyDown will not work - I have tried this routine:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 114 Then
If Me.cmdRelease.Visible = True Then
Me.cmdRelease.Visible = False
Else
Me.cmdMarkAll.Visible = True
End If
End If
End Sub

This will not work..

When using: debug.print KeyAscii on a textbox.keypressed event, I found that Alt-r is 114.

Regards..
 
KeyCode for R - 82
Shift for Alt - 4

If this AND that
 
Here's how to trap the combination

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = acAltMask And KeyCode = 82 Then
 [COLOR="Red"]'[B]Code goes here[/B][/COLOR]
  [B][COLOR="Blue"]KeyCode = 0[/COLOR][/B]
 End If
End Sub

The line in Blue is needed because <Alt> + <R> has a native Access function (drops down the Records Menu) and setting the KeyCode it to Zero cancels this.

Linq ;0)>
 
Thanks for replay.

There must be something I am missing.
I tried the code in both the main form and one of the subform (one of the form in navigationforms), but the only thing happes, is the popup from Access it self stating the Alt-r is an Office key sequence.. (in norewegian - i dont know what it would say in engelish)-

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = acAltMask And KeyCode = 82 Then
'Code goes here
If Me.cmdRelease.Visible = True Then
Me.cmdRelease.Visible = False
Else
Me.cmdRelease.Visible = True
End If

KeyCode = 0

End If

End Sub

Anyway, I believe if another controll have focus, this control.keypress take control over the form.keydowvn event, so this will not be what I want.

In the realy - realy good old days when I was playing with FoxPro, I had the posibility to make a global InKey() whith predifined global shortcuts.
This is what I tries to make, I just don't know how...

Regards.
 
There must be something I am missing.
I tried the code in both the main form and one of the subform (one of the form in navigationforms), but the only thing happes, is the popup from Access it self stating the Alt-r is an Office key sequence.. (in norewegian - i dont know what it would say in engelish)-
I believe this was what missinglinq was talking about.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = acAltMask And KeyCode = 82 Then
KeyCode = 0
If Me.cmdRelease.Visible = True Then
Me.cmdRelease.Visible = False
Else
Me.cmdRelease.Visible = True
End If
End If
End Sub
What happens when you move KeyCode = 0 up there?

Anyway, I believe if another controll have focus, this control.keypress take control over the form.keydowvn event, so this will not be what I want.
Not the case. The form's Keydown supercedes the control's Keydown event. So it's acting as a global Keydown event handler.
 

Users who are viewing this thread

Back
Top Bottom