Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Geoff,
I am probably not fully following you as I cannot reproduce the problem,. but I wonder if it is caused by cascading events. Try amending the code in this manner Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private mEnableEvents As Boolean Private Sub optYes_Enter() If Not mEnableEvents Then mEnableEvents = False If GetAsyncKeyState(vbKeyMenu) And &H8000 Then optYes.Value = True End If mEnableEvents = True End If End Sub Private Sub optYes_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Not mEnableEvents Then mEnableEvents = False If KeyCode = Asc(UCase(lblYes.Accelerator)) And Shift = 4 Then optYes.Value = True End If mEnableEvents = True End If End Sub -- HTH Bob Phillips "Geoff" wrote in message ... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Hi Bob
I applied the suggestion and the results we with optYes - no action with optNo - still the error 'Could not set the visible property. Unexpected call to method or property access'. Meant to mention that in my first post. Anything further thoughts would be appreciated. Geoff "Bob Phillips" wrote: Geoff, I am probably not fully following you as I cannot reproduce the problem,. but I wonder if it is caused by cascading events. Try amending the code in this manner Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private mEnableEvents As Boolean Private Sub optYes_Enter() If Not mEnableEvents Then mEnableEvents = False If GetAsyncKeyState(vbKeyMenu) And &H8000 Then optYes.Value = True End If mEnableEvents = True End If End Sub Private Sub optYes_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Not mEnableEvents Then mEnableEvents = False If KeyCode = Asc(UCase(lblYes.Accelerator)) And Shift = 4 Then optYes.Value = True End If mEnableEvents = True End If End Sub -- HTH Bob Phillips "Geoff" wrote in message ... 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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Geoff,
Could post the whole form code in one full set? And also re-explain the controls, what the controls are, their name, containers, etc? Thanks Bob "Geoff" wrote in message ... Hi Bob I applied the suggestion and the results we with optYes - no action with optNo - still the error 'Could not set the visible property. Unexpected call to method or property access'. Meant to mention that in my first post. Anything further thoughts would be appreciated. Geoff "Bob Phillips" wrote: Geoff, I am probably not fully following you as I cannot reproduce the problem,. but I wonder if it is caused by cascading events. Try amending the code in this manner Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private mEnableEvents As Boolean Private Sub optYes_Enter() If Not mEnableEvents Then mEnableEvents = False If GetAsyncKeyState(vbKeyMenu) And &H8000 Then optYes.Value = True End If mEnableEvents = True End If End Sub Private Sub optYes_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Not mEnableEvents Then mEnableEvents = False If KeyCode = Asc(UCase(lblYes.Accelerator)) And Shift = 4 Then optYes.Value = True End If mEnableEvents = True End If End Sub -- HTH Bob Phillips "Geoff" wrote in message ... 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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Hi Bob
This part of the project is nearly 3,500 lines long. I could maybe email this part to you if you wish to put my question into context? It is reasonably commented. Geoff "Bob Phillips" wrote: Geoff, Could post the whole form code in one full set? And also re-explain the controls, what the controls are, their name, containers, etc? Thanks Bob "Geoff" wrote in message ... Hi Bob I applied the suggestion and the results we with optYes - no action with optNo - still the error 'Could not set the visible property. Unexpected call to method or property access'. Meant to mention that in my first post. Anything further thoughts would be appreciated. Geoff "Bob Phillips" wrote: Geoff, I am probably not fully following you as I cannot reproduce the problem,. but I wonder if it is caused by cascading events. Try amending the code in this manner Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private mEnableEvents As Boolean Private Sub optYes_Enter() If Not mEnableEvents Then mEnableEvents = False If GetAsyncKeyState(vbKeyMenu) And &H8000 Then optYes.Value = True End If mEnableEvents = True End If End Sub Private Sub optYes_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Not mEnableEvents Then mEnableEvents = False If KeyCode = Asc(UCase(lblYes.Accelerator)) And Shift = 4 Then optYes.Value = True End If mEnableEvents = True End If End Sub -- HTH Bob Phillips "Geoff" wrote in message ... 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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Okay, give a try.
-- HTH Bob Phillips "Geoff" wrote in message ... Hi Bob This part of the project is nearly 3,500 lines long. I could maybe email this part to you if you wish to put my question into context? It is reasonably commented. Geoff "Bob Phillips" wrote: Geoff, Could post the whole form code in one full set? And also re-explain the controls, what the controls are, their name, containers, etc? Thanks Bob "Geoff" wrote in message ... Hi Bob I applied the suggestion and the results we with optYes - no action with optNo - still the error 'Could not set the visible property. Unexpected call to method or property access'. Meant to mention that in my first post. Anything further thoughts would be appreciated. Geoff "Bob Phillips" wrote: Geoff, I am probably not fully following you as I cannot reproduce the problem,. but I wonder if it is caused by cascading events. Try amending the code in this manner Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private mEnableEvents As Boolean Private Sub optYes_Enter() If Not mEnableEvents Then mEnableEvents = False If GetAsyncKeyState(vbKeyMenu) And &H8000 Then optYes.Value = True End If mEnableEvents = True End If End Sub Private Sub optYes_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Not mEnableEvents Then mEnableEvents = False If KeyCode = Asc(UCase(lblYes.Accelerator)) And Shift = 4 Then optYes.Value = True End If mEnableEvents = True End If End Sub -- HTH Bob Phillips "Geoff" wrote in message ... 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 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Working on it
Geoff "Bob Phillips" wrote: Okay, give a try. -- HTH Bob Phillips "Geoff" wrote in message ... Hi Bob This part of the project is nearly 3,500 lines long. I could maybe email this part to you if you wish to put my question into context? It is reasonably commented. Geoff "Bob Phillips" wrote: Geoff, Could post the whole form code in one full set? And also re-explain the controls, what the controls are, their name, containers, etc? Thanks Bob "Geoff" wrote in message ... Hi Bob I applied the suggestion and the results we with optYes - no action with optNo - still the error 'Could not set the visible property. Unexpected call to method or property access'. Meant to mention that in my first post. Anything further thoughts would be appreciated. Geoff "Bob Phillips" wrote: Geoff, I am probably not fully following you as I cannot reproduce the problem,. but I wonder if it is caused by cascading events. Try amending the code in this manner Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private mEnableEvents As Boolean Private Sub optYes_Enter() If Not mEnableEvents Then mEnableEvents = False If GetAsyncKeyState(vbKeyMenu) And &H8000 Then optYes.Value = True End If mEnableEvents = True End If End Sub Private Sub optYes_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Not mEnableEvents Then mEnableEvents = False If KeyCode = Asc(UCase(lblYes.Accelerator)) And Shift = 4 Then optYes.Value = True End If mEnableEvents = True End If End Sub -- HTH Bob Phillips "Geoff" wrote in message ... 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 |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Bob
Tried to send to email as noted in the discussion group info. It has failed twice can you assist please. Geoff "Bob Phillips" wrote: Geoff, I am probably not fully following you as I cannot reproduce the problem,. but I wonder if it is caused by cascading events. Try amending the code in this manner Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private mEnableEvents As Boolean Private Sub optYes_Enter() If Not mEnableEvents Then mEnableEvents = False If GetAsyncKeyState(vbKeyMenu) And &H8000 Then optYes.Value = True End If mEnableEvents = True End If End Sub Private Sub optYes_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Not mEnableEvents Then mEnableEvents = False If KeyCode = Asc(UCase(lblYes.Accelerator)) And Shift = 4 Then optYes.Value = True End If mEnableEvents = True End If End Sub -- HTH Bob Phillips "Geoff" wrote in message ... 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 |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Geoff,
try bob dot phillips at tiscali dot co dot uk do the obvious with dot and at words. -- HTH Bob Phillips "Geoff" wrote in message ... Bob Tried to send to email as noted in the discussion group info. It has failed twice can you assist please. Geoff "Bob Phillips" wrote: Geoff, I am probably not fully following you as I cannot reproduce the problem,. but I wonder if it is caused by cascading events. Try amending the code in this manner Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private mEnableEvents As Boolean Private Sub optYes_Enter() If Not mEnableEvents Then mEnableEvents = False If GetAsyncKeyState(vbKeyMenu) And &H8000 Then optYes.Value = True End If mEnableEvents = True End If End Sub Private Sub optYes_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Not mEnableEvents Then mEnableEvents = False If KeyCode = Asc(UCase(lblYes.Accelerator)) And Shift = 4 Then optYes.Value = True End If mEnableEvents = True End If End Sub -- HTH Bob Phillips "Geoff" wrote in message ... 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 |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Hi,
it seems that a control which has focus cannot be hidden in some event procedures. i don't have good things but this is a way that i use, as a last resort, 'standard module Sub HideControl() UserForm1.optYes.Visible = False UserForm1.optNo.Visible = False End Sub 'UserForm1 Private Sub optYes_Change() If optYes.Value Then cboVehReg.Enabled = True lblYes.Visible = False lblNo.Visible = False 'optYes.Visible = False 'optNo.Visible = False 'hide controls after this sequence ends Application.OnTime Now(), "HideControl" txt2.SetFocus End If End Sub -- HTH okaizawa Geoff wrote: 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 |
#11
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Hi
I too thought it may be a timing issue but the interesting thing now is the HideControl sub is not being called. There is no error now as the proc is not being called and therefore there is no attempt to hide the buttons. It is at the hide point the Visible error occurs. Wonder why HideControl is not called despite the line Application.Ontime being read. My bet now is that focus is off doing something somewhere. But where?? I appreciate your further help. Geoff "okaizawa" wrote: Hi, it seems that a control which has focus cannot be hidden in some event procedures. i don't have good things but this is a way that i use, as a last resort, 'standard module Sub HideControl() UserForm1.optYes.Visible = False UserForm1.optNo.Visible = False End Sub 'UserForm1 Private Sub optYes_Change() If optYes.Value Then cboVehReg.Enabled = True lblYes.Visible = False lblNo.Visible = False 'optYes.Visible = False 'optNo.Visible = False 'hide controls after this sequence ends Application.OnTime Now(), "HideControl" txt2.SetFocus End If End Sub -- HTH okaizawa Geoff wrote: 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 |
#12
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Hi,
Geoff wrote: I too thought it may be a timing issue but the interesting thing now is the HideControl sub is not being called. There is no error now as the proc is not being called and therefore there is no attempt to hide the buttons. It is at the hide point the Visible error occurs. set a break point on the line: Application.OnTime Now(), "HideControl" If the macro stops at the point, the procedure name might be different or conflict. try something like: (assuming 'HideControl' is in 'Module1' in the same workbook) Application.OnTime Now, "'" & ThisWorkbook.Name & "'!Module1.HideControl" -- HTH, okaizawa |
#13
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Hi
In short - still no. In both cases the optNo proc completes but without calling for HideControl. Therefore no error is generated but the buttons remian visible. One thing I had not mentioned before; my original code for optYes_Change included a LookUp function. Since using the GetAsyncKeyState code I have had to place this function in the new optYes_Enter event else an error was generated in the optYes_Change event Private Sub OptYes_Enter() If GetAsyncKeyState(vbKeyMenu) And &H8000 Then optYes.Value = True OpenSpeedo = WorksheetFunction.VLookup(cboVehReg.Value, Sheets(3).Range("G1").CurrentRegion, 3, False) End Sub It seems as though only certain things can be done within the optbutton change event under these circumstances. In numerous new code tests I have also had problems with SetFocus statements. The curious thing of course is the original code worked with the mouse. The differences in execution a in the mouseup event, focus will be directed to the optbutton, disregarding where it was prior to the click, the procedure completes but focus is not returned to the previous position. In other words the mouse click forces a 'GotFocus' condition. Maybe with the GetAsyncKeyState code, focus may well be only diverted and the previous control has not 'LostFocus'. This might explain the SetFocus problems. But I do not understand why some statements are executed in the optNo proc. What is different about Visible and VLookup. With VLookup it seems reasonable to propose that focus is being switched to another object ie the worksheet but can that be said of the Visible property? I shall focus my efforts on focus mechanics:):) Thanks so far Geoff "okaizawa" wrote: Hi, Geoff wrote: I too thought it may be a timing issue but the interesting thing now is the HideControl sub is not being called. There is no error now as the proc is not being called and therefore there is no attempt to hide the buttons. It is at the hide point the Visible error occurs. set a break point on the line: Application.OnTime Now(), "HideControl" If the macro stops at the point, the procedure name might be different or conflict. try something like: (assuming 'HideControl' is in 'Module1' in the same workbook) Application.OnTime Now, "'" & ThisWorkbook.Name & "'!Module1.HideControl" -- HTH, okaizawa |
#14
Posted to microsoft.public.excel.programming
|
|||
|
|||
Firing Click Events with Accelerators
Hi
Ok we have resolved the issue - at least a good part of it. With scenario 1, optYes and optNo, the control cboVehReg is responsible for calling the optbuttons and it has an Exit event with a Cancel=True statement. If optNo is selected, focus is switched back to cboVehReg, its data string is cancelled and because of that Cancel = True and focus remains there. I found if I placed the optNo.Visible=False in the cboVehReg_Exit event everything worked as required. With scenario 2, the single button to simply hide itself. There are no Exit events prior to the optbutton call so I used your suggested Application. Ontime statement. This worked. Whether the errors were caused by focus or time is still not entirely clear but at least now I have 2 methods with which to tackle the rest of the projects optbuttons. Many thanks for the original suggestion and for staying with the problem which then emerged. Like another correspondent stated in the 'msgbox transient' thread I am very grateful to the participants of this group for the tremendous support it gives to the little guy. Thank you also Bob for the kindness in looking at the form as a whole by email, I shall respond further by email. Geoff "Geoff" wrote: Hi In short - still no. In both cases the optNo proc completes but without calling for HideControl. Therefore no error is generated but the buttons remian visible. One thing I had not mentioned before; my original code for optYes_Change included a LookUp function. Since using the GetAsyncKeyState code I have had to place this function in the new optYes_Enter event else an error was generated in the optYes_Change event Private Sub OptYes_Enter() If GetAsyncKeyState(vbKeyMenu) And &H8000 Then optYes.Value = True OpenSpeedo = WorksheetFunction.VLookup(cboVehReg.Value, Sheets(3).Range("G1").CurrentRegion, 3, False) End Sub It seems as though only certain things can be done within the optbutton change event under these circumstances. In numerous new code tests I have also had problems with SetFocus statements. The curious thing of course is the original code worked with the mouse. The differences in execution a in the mouseup event, focus will be directed to the optbutton, disregarding where it was prior to the click, the procedure completes but focus is not returned to the previous position. In other words the mouse click forces a 'GotFocus' condition. Maybe with the GetAsyncKeyState code, focus may well be only diverted and the previous control has not 'LostFocus'. This might explain the SetFocus problems. But I do not understand why some statements are executed in the optNo proc. What is different about Visible and VLookup. With VLookup it seems reasonable to propose that focus is being switched to another object ie the worksheet but can that be said of the Visible property? I shall focus my efforts on focus mechanics:):) Thanks so far Geoff "okaizawa" wrote: Hi, Geoff wrote: I too thought it may be a timing issue but the interesting thing now is the HideControl sub is not being called. There is no error now as the proc is not being called and therefore there is no attempt to hide the buttons. It is at the hide point the Visible error occurs. set a break point on the line: Application.OnTime Now(), "HideControl" If the macro stops at the point, the procedure name might be different or conflict. try something like: (assuming 'HideControl' is in 'Module1' in the same workbook) Application.OnTime Now, "'" & ThisWorkbook.Name & "'!Module1.HideControl" -- HTH, okaizawa |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Deactivate Events not Firing | Excel Programming | |||
Excel App. level events not firing | Excel Programming | |||
class events stop firing with ADO 2.8 | Excel Programming | |||
Click events on charts | Excel Programming | |||
Events firing willy nilly | Excel Programming |