ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   EnableEvents problem (https://www.excelbanter.com/excel-programming/399286-enableevents-problem.html)

avi

EnableEvents problem
 
Hello,

I have a form that contains an OptionButton that I want to initialize
as true

In order to disable the message box I code it like that

Sub userform_initialize()
Application.EnableEvents = False
OptionButton1.Value = True
Application.EnableEvents = True
End Sub

Private Sub OptionButton1_Click()
MsgBox "Fired!"
End Sub

When the userform is loaded, i expect not to see the msgbox as events
are disabled. The msgbox still appears. Do I miss something?

Thanks
Avi


Bob Flanagan

EnableEvents problem
 
You could try the following:

'at top of module
bFire as boolean

Sub userform_initialize()
bFire = false
OptionButton1.Value = True
bFire = True
End Sub

Private Sub OptionButton1_Click()
if bFire then MsgBox "Fired!"
End Sub

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel


"avi" wrote in message
ups.com...
Hello,

I have a form that contains an OptionButton that I want to initialize
as true

In order to disable the message box I code it like that

Sub userform_initialize()
Application.EnableEvents = False
OptionButton1.Value = True
Application.EnableEvents = True
End Sub

Private Sub OptionButton1_Click()
MsgBox "Fired!"
End Sub

When the userform is loaded, i expect not to see the msgbox as events
are disabled. The msgbox still appears. Do I miss something?

Thanks
Avi




Dave Peterson

EnableEvents problem
 
This is not an application event.

But you can create your own boolean value that keeps track if you want something
to run (or not run):

Option Explicit
Dim BlkProc As Boolean
Private Sub Userform_Initialize()
BlkProc = True
Me.OptionButton1.Value = True
BlkProc = False
End Sub
Private Sub OptionButton1_Click()
If BlkProc = True Then Exit Sub
MsgBox "Fired!"
End Sub

Or you could change the .value property of that OptionButton to True while in
design mode.
Select the option button
hit F4 to see its properties
change the .value property to true.



avi wrote:

Hello,

I have a form that contains an OptionButton that I want to initialize
as true

In order to disable the message box I code it like that

Sub userform_initialize()
Application.EnableEvents = False
OptionButton1.Value = True
Application.EnableEvents = True
End Sub

Private Sub OptionButton1_Click()
MsgBox "Fired!"
End Sub

When the userform is loaded, i expect not to see the msgbox as events
are disabled. The msgbox still appears. Do I miss something?

Thanks
Avi


--

Dave Peterson

avi

EnableEvents problem
 
Thanks for your good advices

Avi



All times are GMT +1. The time now is 08:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com