LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Firing Click Events with Accelerators

Following on from an earlier thread which asked how to select an optbutton
and fire its click event from the keyboard, a new issue arises. No criticism
is intended on the suggested code and I hope the contributor is able to see
this new thread.

In contrast to the more conventional method of keying in the button's
accelerator then spacebar to fire the click event, I used the suggested code
which avoids the spacebar as reducing keyboard effort is a desirable aim.

For brevity 1 button is shown as the last 2 subs are repeated with relevant
name changes for each new button required.

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As
Long) As Integer

Private Sub optYes_Enter()
If GetAsyncKeyState(vbKeyMenu) And &H8000 Then optYesValue =
True
End Sub

Private Sub optYes_KeyDown(ByVal KeyCode As
MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = Asc(UCase(lblYes.Accelerator)) And Shift = 4 Then
optYes.Value = True
End Sub

There are 2 scenarios:
1. 2 optbuttons, Yes and No, with appropriate labels. Function is to
provide choice to amend either a txtbox or combobox data. On selection,
focus is switched to the relevant control and the optbuttons hidden. An
accelerator key is attached to the label (not optbutton caption) and the tab
order is correctly sequenced to suit.
2. 1 optbutton which hides the frame in which it is located.

All 3 click events fire correctly using the mouse. Disarmingly, all 3 work
when using the conventional method of accelerator then spacebar:):) Using
the code above 1 event works but 2 fail at the point when trying to hide the
buttons.

Click events:
Private Sub optYes_Change() 'Works as expected
cboVehReg.Enabled = True
lblYes.Visible = False
lblNo.Visible = False
optYes.Visible = False
optNo.Visible = False
txt2.SetFocus
End Sub

Private Sub optNo_Change()
cboVehReg.Enabled = True
lblYes.Visible = False
lblNo.Visible = False
optYes.Visible = False
optNo.Visible = False 'Fails here
cboVehReg.Value = ""
cboVehReg.SetFocus
End Sub

The 3rd event in scenario 2 is similar.

I could understand if the cause of failure was in trying to hide the buttons
'recursively' ie before the control has lost focus but that works succesfully
in the other 2 handling methods. It also works with 1 button using this
method. Paradoxically it is the button that works which becomes the anomaly.

Does anyone knows what's happening here? I would appreciate your views.

T.I.A.

Geoff
 
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
Deactivate Events not Firing William Excel Programming 12 July 5th 05 05:12 AM
Excel App. level events not firing Chris W. Excel Programming 1 February 28th 05 03:44 AM
class events stop firing with ADO 2.8 ThankYou_jeff Excel Programming 4 November 14th 04 10:59 AM
Click events on charts Steve Excel Programming 3 May 29th 04 03:26 AM
Events firing willy nilly Darren Hill[_2_] Excel Programming 4 January 23rd 04 10:00 PM


All times are GMT +1. The time now is 12:24 AM.

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"