Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

How to tie some vba code to a function key

When I have the cursor in a specific text box on a specific form (and only then) I would like to be able to click F5 and run some code.  How can I do that please?
0
snyperj
Asked:
snyperj
1 Solution
 
Dale FyeCommented:
You can set the KeyPreview Property of the form to true.

Then put code in the KeyDown event of your textbox, similar to:

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

    if KeyCode = vbKeyF5 Then
        'put your code here

         'the reset the keycode
         KeyCode = 0
    endif

End Sub
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now