Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Can't trigger Keydown event

I got a form with a MultiPage control, and haven't been able to find a way to change tabs without using the mouse. I'd like to use some key combination, perhaps Ctrl + vbKeyLeft or vbKeyRight. Ideally the key command should work no matter what control has focus. How does all that sound in terms of usability and best practices?

The immediate problem now is that the code I wrote won't trigger switching the tabs. There are 2 tabs:

' Allow shifting tabs with arrow keys
Private Sub MultiPage1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)

If Shift = 2 And KeyCode = vbKeyLeft Then
If MultiPage1.Value = 1 Then
Exit Sub
Else
MultiPage1.Value = 0
End If
End If

If Shift = 2 And KeyCode = vbKeyRight Then
If MultiPage1.Value = 0 Then
Exit Sub
Else
MultiPage1.Value = 1
End If
End If

End Sub

Hope someone can spot the error here.

Gustaf
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Can't trigger Keydown event

This will work better :-)

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

If Shift = 2 And KeyCode = vbKeyLeft Then
If MultiPage1.Value = 0 Then
Exit Sub
Else
MultiPage1.Value = 0
End If
End If

If Shift = 2 And KeyCode = vbKeyRight Then
If MultiPage1.Value = 1 Then
Exit Sub
Else
MultiPage1.Value = 1
End If
End If

End Sub


RBS


"Gustaf" wrote in message
...
I got a form with a MultiPage control, and haven't been able to find a way
to change tabs without using the mouse. I'd like to use some key
combination, perhaps Ctrl + vbKeyLeft or vbKeyRight. Ideally the key
command should work no matter what control has focus. How does all that
sound in terms of usability and best practices?

The immediate problem now is that the code I wrote won't trigger switching
the tabs. There are 2 tabs:

' Allow shifting tabs with arrow keys
Private Sub MultiPage1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)

If Shift = 2 And KeyCode = vbKeyLeft Then
If MultiPage1.Value = 1 Then
Exit Sub
Else
MultiPage1.Value = 0
End If
End If
If Shift = 2 And KeyCode = vbKeyRight Then
If MultiPage1.Value = 0 Then
Exit Sub
Else
MultiPage1.Value = 1
End If
End If

End Sub

Hope someone can spot the error here.

Gustaf


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Can't trigger Keydown event

Thank you, it works, but only if I put the event on the textbox that gets focus when the form loads rather than the multipage. It seems there's no way to give focus to the multipage or form itself. Is there a way to attach the event to all controls on the form, without actually writing separate events for each control?

Gustaf

RB Smissaert wrote:
This will work better :-)

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

If Shift = 2 And KeyCode = vbKeyLeft Then
If MultiPage1.Value = 0 Then
Exit Sub
Else
MultiPage1.Value = 0
End If
End If

If Shift = 2 And KeyCode = vbKeyRight Then
If MultiPage1.Value = 1 Then
Exit Sub
Else
MultiPage1.Value = 1
End If
End If

End Sub


RBS


"Gustaf" wrote in message
...
I got a form with a MultiPage control, and haven't been able to find a
way to change tabs without using the mouse. I'd like to use some key
combination, perhaps Ctrl + vbKeyLeft or vbKeyRight. Ideally the key
command should work no matter what control has focus. How does all
that sound in terms of usability and best practices?

The immediate problem now is that the code I wrote won't trigger
switching the tabs. There are 2 tabs:

' Allow shifting tabs with arrow keys
Private Sub MultiPage1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)

If Shift = 2 And KeyCode = vbKeyLeft Then
If MultiPage1.Value = 1 Then
Exit Sub
Else
MultiPage1.Value = 0
End If
End If
If Shift = 2 And KeyCode = vbKeyRight Then
If MultiPage1.Value = 0 Then
Exit Sub
Else
MultiPage1.Value = 1
End If
End If

End Sub

Hope someone can spot the error here.

Gustaf


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
keydown event Peter T Excel Programming 0 April 18th 05 02:03 PM
keydown event K Dales[_2_] Excel Programming 0 April 18th 05 12:46 PM
user form-on open event? keydown event? FSt1[_3_] Excel Programming 2 August 5th 04 02:26 PM
keydown event jim c. Excel Programming 1 October 10th 03 03:16 AM


All times are GMT +1. The time now is 04:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"