Results 1 to 3 of 3

Thread: Key Press Problem

  1. #1

    Thread Starter
    Addicted Member Ramandeep's Avatar
    Join Date
    Feb 2000
    Posts
    158

    Question

    Can any one tell me why this isn't working?
    Code:
    Private Sub Form_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyUp Then
            KeyAscii = 0
            Debug.Print "Up Key Pressed"
            Beep
        End
        
        If KeyAscii = vbKeyDown Then
            KeyAscii = 0
            Debug.Print "Down Key Pressed"
            Beep
        End If
    End Sub
    This is just a test i wrote for another program just to see if the keys etc work, but nothing happens no beeps and no text is being printed in th debug dialog...help?

    I have also tried the keyDown & keyUp procedures still nothing.

  2. #2
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Worldwide in the Sun
    Posts
    566
    Try this

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If (KeyCode = vbKeydown) Then
    MsgBox "Down key pressed"
    End If
    If (KeyCode = vbKeyup) Then
    MsgBox "Up key pressed"
    End If

    End Sub


    Cheers
    Ray
    Ray

  3. #3
    Lively Member
    Join Date
    Oct 2000
    Location
    Chicago
    Posts
    97
    The first thing that you have to do is to set the KeyPreview property to True then the second thing is that your code will work fine if you have controls like textbox or listbox in the form.If you click inside that then you will get the output desired by you....
    Anil

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width