2

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

T.M.
  • 9,436
  • 3
  • 33
  • 57
Philip Day
  • 69
  • 7
  • Any event code in your MultiPage control ? – Tim Williams Mar 18 '19 at 22:38
  • 2
    Sounds like `.TabStop` and `.TabOrder` is what you want to look at. Setting `.TabStop = No` should stop the cursor from automatically going there. The reason the next textbox becomes the problem is because that is the control with the lowest `.TabOrder` so it gets the focus by default. https://support.office.com/en-us/article/set-the-tab-order-for-controls-2b37e49b-52d1-4f03-ae33-9e6d9c103c99 – HackSlash Mar 18 '19 at 22:47
  • @HackSlash this sounds like it could be the answer to my prayers. Looking into this, do I need to set each of those textboxes' settings individually? A la: TextBoxTEST1.Tabstop = False or can I use MultiPage1.TabStop = False successfully? – Philip Day Mar 18 '19 at 22:57
  • Yes, each one needs `.TabStop = No` and you must manually configure the `.TabOrder` to put the controls in the order which you would like them to be selected automatically. One flowing in to the next. – HackSlash Mar 18 '19 at 22:58
  • Doh, that would have been really helpful to know before I had well over 300 textboxes to edit. Is there definitely no other way @HackSlash? – Philip Day Mar 18 '19 at 23:06
  • There are posts here that have solutions for dynamic userform controls... – PatricK Mar 19 '19 at 06:26
  • Yeah, you can do it with code by looping through all controls. OR you can select them all and the change will affect all selected objects. – HackSlash Mar 19 '19 at 16:40
  • Posted a work around consisting of only a few code lines (for 6 dummy textboxes) - @PhilipDay – T.M. Mar 19 '19 at 20:55

1 Answers1

1

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.

T.M.
  • 9,436
  • 3
  • 33
  • 57