PC Review


Reply
Thread Tools Rate Thread

ActiveX Control Return Keypress MsgBox Loop

 
 
=?Utf-8?B?dG9tZ3JlZW4xMDAw?=
Guest
Posts: n/a
 
      20th Jul 2007
A simplified version of my problem. Consider a single command button on a
blank worksheet. I want to be able execute the command button Click event
with both the Return key and a mouse click. I want to be able to clear the
message box with both the Return key and a mouse click. If I try to clear the
message box with the Return key, it also executes the command button Click
event again. So using the Return key to clear the message box puts you into
a loop. Any ideas are greatly appreciated.

Thanks, Tom

'In ThisWorkbook
Private Sub Workbook_Open()
Sheet1.Button1.Activate
End Sub

'In Sheet1
Private Sub Button1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Select Case KeyCode
'Return is only key press that we care about
Case vbKeyReturn
Call Button1_Click
End Select
End Sub
Private Sub Button1_Click()
MsgBox "I am stuck in a loop when I use the Return key to clear this message
box" & vbNewLine & "but everything is fine if I use a mouse click to clear
this message box"
End Sub
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QW5vbnk=?=
Guest
Posts: n/a
 
      20th Jul 2007
Just two ideas:
1) Deactivate the button after you've clicked it and activate again it after
you've closed the Msgbox.
2) Declare a global boolean variable, say BtnClicked. Start by setting
BtnClicked as False. In your Button1_Click procedure, set BtnClicked to
True. Based on that, conditionally disable parts of the procedure as needed.
And with the message box, if the user clicks OK, reset the boolean variable
back to False.

Hope that helps,
Anony
 
Reply With Quote
 
=?Utf-8?B?dG9tZ3JlZW4xMDAw?=
Guest
Posts: n/a
 
      21st Jul 2007
Thanks for the very helpful suggestions. I have tried both of them with a
limited degree of success. I think my problem is that I do not know with
what Event to re-activate the button or reset the boolean variable. Given
the choice, I would like to do this with deactivating and re-activating the
button. I prefer this method because in the actual workbook that I am
dealing with, there are around 20 instances of this problem. Any guidance
about the location and or event for reactivating the button or resetting the
boolean is appreciated.

Regards, Tom

-----------------------
'Attempt to deactivate control
Private Sub Button1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Select Case KeyCode
'Return is only key press that we care about
Case vbKeyReturn
Call Button1_Click
End Select
End Sub
Private Sub Button1_Click()
'Deactivate Button1
Sheet1.Range("A1").Select
msg = MsgBox("Trying with deactivation")
End Sub
'where to re-activate Button1?
-------------------------------
'Attempt to flag with global boolean variable
'Public BtnClicked As Boolean in Module1
Private Sub Worksheet_Activate()
BtnClicked = False
End Sub
Private Sub Button1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If BtnClicked = False Then
Select Case KeyCode
'Return is only key press that we care about
Case vbKeyReturn
Call Button1_Click
End Select
End If
End Sub
Private Sub Button1_Click()
BtnClicked = True
msg = MsgBox("Trying with global boolean variable")
End Sub
'where to reset BtnClicked = False?
----------------------------------------
"Anony" wrote:

> Just two ideas:
> 1) Deactivate the button after you've clicked it and activate again it after
> you've closed the Msgbox.
> 2) Declare a global boolean variable, say BtnClicked. Start by setting
> BtnClicked as False. In your Button1_Click procedure, set BtnClicked to
> True. Based on that, conditionally disable parts of the procedure as needed.
> And with the message box, if the user clicks OK, reset the boolean variable
> back to False.
>
> Hope that helps,
> Anony

 
Reply With Quote
 
=?Utf-8?B?QW5vbnk=?=
Guest
Posts: n/a
 
      3rd Aug 2007
Sorry it took so long to get to you, you probably already has the problem
figured out by now.
But in case you haven't, I'd reactivate the button after you've cleared the
message box, assuming that was what you were trying to accomplish in the
first place with the return key.

------
Cheers,
Anony


"tomgreen1000" wrote:

> Thanks for the very helpful suggestions. I have tried both of them with a
> limited degree of success. I think my problem is that I do not know with
> what Event to re-activate the button or reset the boolean variable. Given
> the choice, I would like to do this with deactivating and re-activating the
> button. I prefer this method because in the actual workbook that I am
> dealing with, there are around 20 instances of this problem. Any guidance
> about the location and or event for reactivating the button or resetting the
> boolean is appreciated.
>
> Regards, Tom
>
> -----------------------
> 'Attempt to deactivate control
> Private Sub Button1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
> Shift As Integer)
> Select Case KeyCode
> 'Return is only key press that we care about
> Case vbKeyReturn
> Call Button1_Click
> End Select
> End Sub
> Private Sub Button1_Click()
> 'Deactivate Button1
> Sheet1.Range("A1").Select
> msg = MsgBox("Trying with deactivation")
> End Sub
> 'where to re-activate Button1?
> -------------------------------
> 'Attempt to flag with global boolean variable
> 'Public BtnClicked As Boolean in Module1
> Private Sub Worksheet_Activate()
> BtnClicked = False
> End Sub
> Private Sub Button1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
> Shift As Integer)
> If BtnClicked = False Then
> Select Case KeyCode
> 'Return is only key press that we care about
> Case vbKeyReturn
> Call Button1_Click
> End Select
> End If
> End Sub
> Private Sub Button1_Click()
> BtnClicked = True
> msg = MsgBox("Trying with global boolean variable")
> End Sub
> 'where to reset BtnClicked = False?
> ----------------------------------------
> "Anony" wrote:
>
> > Just two ideas:
> > 1) Deactivate the button after you've clicked it and activate again it after
> > you've closed the Msgbox.
> > 2) Declare a global boolean variable, say BtnClicked. Start by setting
> > BtnClicked as False. In your Button1_Click procedure, set BtnClicked to
> > True. Based on that, conditionally disable parts of the procedure as needed.
> > And with the message box, if the user clicks OK, reset the boolean variable
> > back to False.
> >
> > Hope that helps,
> > Anony

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Return keypress not detected Stuart Kirk Microsoft Dot NET Framework Forms 0 28th Aug 2008 12:53 PM
Trapping Return in keypress() dwetmore@citcom.net Microsoft Access Form Coding 2 9th Jan 2008 08:18 PM
ActiveX Control prompt "An ActiveX control on this page might be u =?Utf-8?B?UmFodWw=?= Windows Vista General Discussion 2 1st Aug 2006 05:08 PM
Pop-up dialog box - Return value on KeyPress Santa-D Microsoft Access Form Coding 3 7th Jul 2006 03:59 AM
RETURN key does not fire KeyDown/KeyPress event =?Utf-8?B?R2VyaGFyZCBLaWVzc2xpbmc=?= Microsoft Access Form Coding 4 14th Dec 2004 12:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:11 PM.