Event still triggers after setting EnableEvents to False

ShieBoon

Board Regular
Joined
May 3, 2011
Messages
111
Hi all, i have a procedure which unloads a userform. When this userform is loaded, one of the textboxes are setfocused on (textbox1.setfocus).

This textbox has validation codes in its BeforeUpdate event. If wrong text is entered, there will be a prompt.

In the procedure i have the following codes.

.
.
.
Application.EnableEvents = False
Unload frm_Userform
Application.EnableEvents = True
.
.
.

Thing is, unloading the userform still triggers the BeforeUpdate event of the textbox. Thus, if there is wrong text, there will be a prompt. And i don't want that prompt to occur in this procedure. Any ideas?

Excel 2003
Thanks
Shie Boon
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Application.EnableEvents does not effect userform events.

One workaround is to introduce a DisableUfEvents variable into the userform's code module.

Code:
Dim DisableUfEvents As Boolean

Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    If DisableUfEvents Then Exit Sub
    '...
End Sub

'...

    DisableUfEvents = True
    Unload frm_Userform
    DisableUfEvents = False
 
Upvote 0

Forum statistics

Threads
1,214,994
Messages
6,122,633
Members
449,092
Latest member
bsb1122

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