PC Review


Reply
Thread Tools Rate Thread

Disable all Control Events on a Userform when it is Intialized

 
 
RyanH
Guest
Posts: n/a
 
      15th Sep 2008
I have a Userform with 17 Checkboxes. Each checkbox has a Click Event that
calls another procedure to calculate values to be displayed in Textboxes on
the Userform depending if the checkbox is true or false. The checkbox value
is determined by values on a particular row in a worksheet. When the
userform is initialized it runs this calculation 17 different times. Is there
a way to disable the events while the form intializes and then when all
values are deterimined in the Userform, then run the Click events? Currently
it is not slow, I was just wondering if it would be faster.

Here is a shortened version of my code. I tried doing this but when I
stepped thru the code it still fires the events.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

With Userform
Checkbox1 = Cells(ActiveCell.Row, "A")
' then Checkbox1_Click Event Fires
Checkbox2 = Cells(ActiveCell.Row, "A")
' then Checkbox2_Click Event Fires
End With

Application.EnableEvents = True

Userform.Show

End Sub

Private Sub UserForm_Initialize()

' load list boxes and other stuff

Application.EnableEvents = False

End Sub
--
Cheers,
Ryan
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      15th Sep 2008
app.EnableEvents does not affect userform control events.

You could set a module level flag and in the first line in each control
event something like this -
If mbDisable the Exit Sub

You could toggle the Enabled property of controls with something like this -

Sub EnableControls(bEnable as boolean)
dim ctr as object

for each ctr in me.controls
if typename(ctr) = blah
' or perhaps
if left$(ctr.name, 5) = "Check" then

ctr.enabled = bEnable
end if
next

if you've got the relevant controls in some logical index order (index order
is the order in which controls were added to the form at design time, it
won't change)

For i = 5 to 10
me.controls(i).enabled = bEnable
next

Regards,
Peter T



"RyanH" <(E-Mail Removed)> wrote in message
news:EDC164C7-F04E-42FC-8248-(E-Mail Removed)...
>I have a Userform with 17 Checkboxes. Each checkbox has a Click Event that
> calls another procedure to calculate values to be displayed in Textboxes
> on
> the Userform depending if the checkbox is true or false. The checkbox
> value
> is determined by values on a particular row in a worksheet. When the
> userform is initialized it runs this calculation 17 different times. Is
> there
> a way to disable the events while the form intializes and then when all
> values are deterimined in the Userform, then run the Click events?
> Currently
> it is not slow, I was just wondering if it would be faster.
>
> Here is a shortened version of my code. I tried doing this but when I
> stepped thru the code it still fires the events.
>
> Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
> Boolean)
>
> With Userform
> Checkbox1 = Cells(ActiveCell.Row, "A")
> ' then Checkbox1_Click Event Fires
> Checkbox2 = Cells(ActiveCell.Row, "A")
> ' then Checkbox2_Click Event Fires
> End With
>
> Application.EnableEvents = True
>
> Userform.Show
>
> End Sub
>
> Private Sub UserForm_Initialize()
>
> ' load list boxes and other stuff
>
> Application.EnableEvents = False
>
> End Sub
> --
> Cheers,
> Ryan



 
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
Disable Userform Events Ryan H Microsoft Excel Programming 1 5th Mar 2009 05:01 PM
Events in a Userform =?Utf-8?B?VHJlZm9y?= Microsoft Excel Programming 2 17th Mar 2006 03:09 PM
UserForm Events Nigel Microsoft Excel Programming 1 22nd Feb 2004 12:19 PM
Disable events programmatically during startup, gain external Automation control Dave Boyd Microsoft Access Form Coding 0 16th Jan 2004 09:33 PM
IE not intialized mellany Windows XP General 1 7th Oct 2003 04:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:57 PM.