View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Geoff Geoff is offline
external usenet poster
 
Posts: 371
Default 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