Results 1 to 6 of 6

Thread: key press event

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Posts
    9

    key press event

    Hi,

    I have a spin button on my form and I need it to scroll up/down depending on which key is pressed (pg up/pg dn). I tried the key press event for the spin button by passing the asci code for the keys, but it doesnt seem to work. I am sure this is the way to do it, but I am not getting it right. I need to know where I have to enter the key code for the pg up/ pg dn buttons.
    Thanks in advance,

    Sunil.

  2. #2
    Hyperactive Member Granty's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    439
    Can you post your code?

  3. #3
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    Make sure the forms key preview is set to true and in the key down event the following will work
    Code:
    if keycode = 33 then 'page up
    'your code here
    else if keycode = 34 then 'page down
    'your code here
    endif

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Posts
    9
    i cannot find the key preview property...8)

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Posts
    9
    heres what I did

    Private Sub spnBtn1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

    If KeyCode = 33 Then
    EntrytoCell
    Set rowno = Cells(ActiveCell.Row - 1, 1)
    rowno.Activate
    CelltoEntry
    Else
    If KeyCode = 34 Then
    EntrytoCell
    Set rowno = Cells(ActiveCell.Row - 1, 1)
    rowno.Activate
    CelltoEntry
    End If
    End If
    End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Posts
    9

    key press event(resolved)

    well kinda, i tried associating the event with a text box and it worked. so whenever im in the text box and i hit the pgup/pgdn button it loads a new record, only problem is that it is obviously not going to work if the focus is on some other object. i tried the forms key press event, but for some reason the control doesnt seem to go to it, but as long as it works with the text box

    Thanks
    Sunil.

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