Solved Selecting automatically a form page select bar after loading (1 Viewer)

JayBee.MT

New member
Local time
Today, 01:52
Joined
Jan 7, 2021
Messages
2
Hello,
I have a numeric keypad menu-driven button in a form. I'm using the Fom_Keydown case loop to capture the numeric buttons pressed from 1 to 9 using vbKeypad. My problem is that I have to select the left form select button for the sub to run. I have difficulty to find the command in VBA that automatically select the from's record select bar as soon as I'm opening the menu form using Form_Load.
I appreciate if you can give me feedback.
Regards,
Joseph
 

Minty

AWF VIP
Local time
Today, 00:52
Joined
Jul 26, 2013
Messages
10,371
Hi Joseph, and welcome to AWF!

Are you on about the record selector on the far left of the detail section?
If not perhaps a picture of what you are referring to would help, and why you need it selected to make you code run, which is also puzzling me?

Maybe move the code to the detail or form header section?
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 19:52
Joined
May 21, 2018
Messages
8,528
Set the key preview property of the form to yes

Syntax​

expression.KeyPreview

expression A variable that represents a Form object.

Remarks​

The KeyPreview property uses the following settings.

REMARKS
SettingVisual BasicDescription
YesTrueThe form receives keyboard events first, and then the active control receives keyboard events.
NoFalse(Default) Only the active control receives keyboard events.
You can set the KeyPreview property in any view.

You can use the KeyPreview property to create a keyboard-handling procedure for a form. For example, when an application uses function keys, setting the KeyPreview property to True allows you to process keystrokes at the form level rather than writing code for each control that might receive keystroke events.

To handle keyboard events only at the form level and prevent controls from receiving keyboard events, set the KeyAscii argument to 0 in the form's KeyPress event procedure, and set the KeyCode argument to 0 in the form's KeyDown and KeyUp event procedures.

If a form has no visible or enabled controls, it automatically receives all keyboard events.

Example​

In the following example, the KeyPreview property is set to True in the form's Load event procedure. This causes the form to receive keyboard events before they are received by any control. The form KeyDown event then checks the KeyCode argument value to determine if the F2, F3, or F4 keys were pushed.

VBCopy

Private Sub Form_Load()
Me.KeyPreview = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF2
' Process F2 key events.
Case vbKeyF3
' Process F3 key events.
Case vbKeyF4
' Process F4 key events.
Case Else
End Select
End Sub
 

Users who are viewing this thread

Top Bottom