Philip Day
Philip Day

Reputation: 69

Application.EnableEvents = False but textbox_Enter sub still firing in multipage userform VBA

I have a multipage userbox called MultiPage1 (as per default).

This comprises 6 pages, all of which have hundreds of textboxes on them, and they all work perfectly...

I have one problem. When Multipage.Value = 3 it seems to launch a textbox_Enter event, no matter what I do to try to ensure that the textbox doesn't have the focus throughout the serial.

I of course tried Application.EnableEvents = False, but I believe that userforms do not trigger events in the traditional sense of the term.

I cannot for the life of me figure out the problem. But it can be replicated on all of the machines that I have tried.

Interestingly.. when I renamed the troublesome textbox by deleting it, and replacing it with a new textbox with the exact same name.. the problem shifted to the next textbox in the sequence.

TextBoxTEST1_Enter no longer fires and now TextBoxTEST2_Enter fires instead.

With over 300 textboxes, I am loath to re-create them all!

Any ideas?!

Many thanks,

Phil

Upvotes: 2

Views: 305

Answers (1)

T.M.
T.M.

Reputation: 9948

Avoid automatic textbox activation

A simple work around consists in assigning zero .Width, zero .Height and zero .TabIndex to only one dummy textbox per page.

A possible naming convention could be Dummy1 on 1st page, Dummy2 on 2nd page etc.

Code example

Private Sub UserForm_Initialize()
    Dim i&
    For i = 1 To Me.MultiPage1.Pages.Count
        Me.Controls("Dummy" & i).Width = 0
        Me.Controls("Dummy" & i).Height = 0
        Me.Controls("Dummy" & i).TabIndex = 0
    Next i
End Sub

Side note

Trying a similar approach moving the dummy textbox out of sight (e.g. via a negative .Left property) fails, as it shows a blinking cursor at the left page border independant from the chosen value.

Upvotes: 1

Related Questions