Simple SetFocus on userform issue

S

SMS

Well, it SOUNDS simple...

Userform with three controls, TextBox1, TextBox2, TextBox3

For TextBox2 ONLY, I have this code:

Private Sub TextBox2_afterupdate()
counter = counter +1
TextBox2.Text = ""
TextBox2.SetFocus
End Sub


This is supposed to increment a counter, clear the textbox... and here
is the pisser: SET THE FOCUS BACK TO TEXTBOX2.

This appears to be impossible... I have spent hours on it.

Please help!

Again, the sole goal here is to get the same text box to have focus
when the event is finished.

Thank you SO much...
 
J

JLGWhiz

I don't understand the problem. If you are using the AfterUpdate event,
which occurs by User Interface changes, then the focus should already be on
the control. What is it doing/or not doing. Where is the focus after the
event?
 
J

JLGWhiz

I believe that if the value window of the textbox is empty, the focus
automatircally goes bacward to the next control with a value, and if they
are all empty it will go to the first index in tab order. But as soon as
you click on the textbox it takes focus.
 
S

SMS

OK, I am a little lost with that...

so what is the method to have the focus retained in the textbox that I
am working in? (I never want the focus to leave for any reason other
than manually clicking away from it).

Thank you...
 
S

SMS

Oh, and I checked the value window idea... and the behavior is the
same, regardless of the content of the textbox.

I will pay $10 to the paypal account of the first person to solve
this... basically, to return the focus to a textbox after that
textbox has had update code executed (for example, clearing the text).
(on a userform with many text boxes, this feature working for any or
all of the textboxes I might wish to implement it on)

To understand WHY this needs to be the way it is, imagine a barcode
reader instead of a keyboard. Imagine thousands of barcodes that need
to be scanned as fast as possible. Imagine that I have the a textbox
that is ready to have the barcode value typed into it from the barcode
reader, and that I want it to respond to whatever value is "typed"
into it (for example, record it) then clear the value, then wait for
the next code.

obviously, focus MUST return to that same text box, or else... well...
I'm dead in the water.

Thank you
 
S

SMS

OK, I have a "solution". It's stupid, but it works.

I am able to set the focus from the textbox afterupdate event code to
any other text box, but EXCEPT the one executing the event.

the solution is to have TWO text boxes... in the same location. Each
one has the same code... but sets the focus to the other one, and at
the same time toggling visiblilty of both textboxes. The effect is
that it looks like the same text box... but really, we are hopping
back and forth between them.

Sigh. Excel usually rocks. This, however, has been a real headache.
I hope this workaround helps others.
 
S

SMS

Interesting Update!!!!

The problem seems to relate to the existance of a FRAME.

If there is a frame object (with tabstop set to true) on the same
userform... then it causes things to fail, even in the case of my
"workaround" solution.

This is some crazy interaction.... is there any rhyme or reason to it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top