Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default toggle button or worksheet_activate causing form to open twice

Let's look at a simplified situation which is probably the cause of your
problem.
If I put in code like

Private Sub ToggleButton1_Click()
MsgBox ToggleButton1.Value
With ToggleButton1
.Caption = "Protect Sheets"
.Value = False
End With
End Sub

then the click event runs twice. When you change the value to False, it
triggers another click.

You would need to do something like


Public bBlockEvents

Private Sub ToggleButton1_Click()
If bBlockEvents Then Exit Sub
bBlockEvents = True
MsgBox ToggleButton1.Value
With ToggleButton1
.Caption = "Protect Sheets"
.Value = False
End With
bBlockEvents = False
End Sub

so i use a public variable to cause the second click event to exit
immediately.

--
Regards,
Tom Ogilvy

"Nicole B" wrote in message
...
I have a userform that prompts for a password. I posted yesterday

regarding
the fact that when I click a button, it runs through a macro, either opens

a
msgbox or opens a userform, then when you click OK to close the userform

(and
run another macro to validate the input), the userform, or message box,
reopens.

I debugged and stepped through the macro (from ProtectionToggle_Click()

Sub
to called macros) and it did not come up twice. Also, I have run the
userform macro from VB and it works fine. It seems to only be a problem

if I
run it from the toggle button in Excel.

I think it may be either the toggle buttons causing the problem or the
Worksheet_Activate macro. Could someone take a look?

Code for Toggle Button:
Private Sub ProtectionToggle_Click()
Application.ScreenUpdating = False
If wkshtInventoryHome.ProtectContents = True Then
With ProtectionToggle
.Caption = "Protect Sheets"
.Value = False
End With
Call RunProtectionPasswordUserForm
ElseIf wkshtInventoryHome.ProtectContents = False Then
Response = MsgBox("Are you sure you want to protect the worksheet?" _
& vbLf & "This action cannot be undone without a password.",
vbOKCancel, _
"Confirm Protect Sheets")
If Response = vbOK Then
With ProtectionToggle
.Caption = "Begin Advanced Editing"
.Value = False
End With
End If
'after button is pressed:
Call WorkbookProtect
End If
Application.ScreenUpdating = True
End Sub

Worksheet Activate:
Private Sub Worksheet_Activate()
If wkshtLumberShores.ProtectContents = True Then
ProtectionToggle.Caption = "Begin Advanced Editing"
ElseIf wkshtLumberShores.ProtectContents = False Then
ProtectionToggle.Caption = "Protect Sheets"
End If
End Sub



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
how do I toggle between 2 open excel files and leave both open Big D in Brighton Excel Discussion (Misc queries) 1 November 6th 08 04:28 PM
Toggle Form Button Copied TKS_Mark Excel Discussion (Misc queries) 1 September 17th 08 05:55 PM
Need to Use 1 Button to toggle On or Off Jim May Excel Discussion (Misc queries) 2 December 1st 07 08:01 PM
use a button to open a user form? Hru48 Excel Discussion (Misc queries) 1 September 1st 05 07:41 PM
Toggle Button Keri[_2_] Excel Programming 2 May 28th 04 04:58 PM


All times are GMT +1. The time now is 05:34 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"