
Setfocus during AfterUpdate for a text box
Quote:
> I'm new to VB programming so I'm betting there will be a
> simple answer for this. I'm performing an edit of some
> data typed in a Textbox on a very simple form. I coded
> the edit in the AfterUpdate event and want to keep the
> focus on this textbox if there is an editing error.
> However, I'm at a loss how to do this. Setting the
> Setfocus property doesn't seem to work, which I do
> understand why, since focus is already on the textbox.
> Any hints or suggestions on how to retain focus on this
> textbox ?
Allen,
Not sure if this will help.
Firstly, an explanation of what's going on.
When you End Sub, VB moves the cursor/focus to the next Tab index if the
focus is in the control you are using.
If focus is elsewhere, it leaves it alone.
Hence, you can't SetFocus to the current control and leave it there.
Secondly, a possible work-around.
I had the same problem.
I have used an InputBox to get the new input if the old one was rejected by
the error checking.
Something like:
If IsNumeric (Text1.Text) Then Text1.Text = InputBox ("Surname cannot
contain numbers. Please re-input")
Thirdly some conjecture.
VB *must* keep a record somewhere of where it is in the Tab index (So that
it knows where to go to next).
Is there a way of altering this record to let you end up where you want to
be?
If it's held as a number, a simple decrement before End Sub would tell it to
go back one tab stop and then it will go forward again at End Sub, leaving
you where you were.
HTH
Henry