How To set a a Function Key to click a cmd?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jiexian
    New Member
    • May 2009
    • 2

    How To set a a Function Key to click a cmd?

    This is what i have

    Code:
    Public Sub Form_Load()
     KeyPreview = True
    End Sub
    Code:
    Private Sub Form_KeyDown(KeyCodeConstants As Integer, Shift As Integer)
    KeyPreview = True
     If KeyCodeConstants = vbKeyF1 Then cmd1_Click
     If KeyCodeConstants = vbKeyF2 Then cmd2_Click
    End Sub
    When i press F1 or F2, i get an error msg "Compile error : Sub or Function not defined"

    Can anyone please help me? Thank you!

    i'm using vb 6.0 enterprise edition
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    In VB6, Form_KeyDown event looks like This :
    (KeyCode Instead of KeyCodeConstant s )

    [code=vb]
    Private Sub Form_KeyDown(Ke yCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF1 Then
    Call cmd1_Click
    ElseIf KeyCode = vbKeyF2 Then
    Call cmd2_Click
    End If
    End Sub
    [/code]

    Regards
    Veena

    Comment

    Working...