Disabling Events in the Initialize subroutine of a UserForm

USAMax

Well-known Member
Joined
May 31, 2006
Messages
843
Office Version
  1. 365
Platform
  1. Windows
In the name of God, will someone please help me as I have never been so frustrated.

I have been at this for two hours and found a very good article: Suppressing Events In UserForms that explains what to do very clearly but NOTHING WORKS.

I created the public variable:
Code:
    Public EnableEvents As Boolean

And I put Me.EnableEvents at the beginning of my Initialize subroutine for the UserForm
Code:
    Private Sub UserForm_Initialize()
        Me.EnableEvents = True
    End Sub

I have tried changing:
1) True to False
2) Me to UserUpdFormEng (The name of the UserForm the Initialize subroutine is for.)

I have Me.EnableEvents = False at the end of the Initialize subroutine.

This is still triggering events within Initialize and I need the events to stop within Initialize.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Did you read the bit about changing the event code for the controls:
Then, all of the controls on form should have a test of that variable as their first order of business in any event code. For example,

Private Sub ListBox1_Change()
If Me.EnableEvents = False Then
Exit Sub
End If
MsgBox "List Box Change"
End Sub
 
Upvote 0
Thank you for getting back to me Rory, I figured it out from reading another article.

It would be much clearer if someone said that there isn't a way to suppress a UserForm event so you need to create a public variable to show you want it suppressed then test for it.

By calling it EnableEvents it makes it look like a VB command thus the confusion.

2.5 hours just to figure that out!

Thank you again Rory.
 
Upvote 0
Quoting Chip's article:
However, Application.EnableEvents does not apply to controls on a UserForm. Changing a control's value will usually cause and event for that control to be execute. For example, change the value of the ListIndex of a ListBox control will cause the ListBox's Change and Click events to fire. Since you are changing the ListIndex in code, you probably don't want the events to run.

To suppress events in a form, you can create a variable at the form's module level called "EnableEvents" and set that to False before changing a property that will cause an event to be raised.

In conjunction with the other part I quoted, it seems pretty much to the point. ;)
 
Upvote 0
You are right, I know I am just arguing semantics but it would have been more clear if it said, "You CANNOT suppress UserForm Events, only manage them."

You are a gentleman for coming to my aid and I thank you.
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,305
Members
449,150
Latest member
NyDarR

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top