Setfocus during AfterUpdate for a text box 
Author Message
 Setfocus during AfterUpdate for a text box

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 ?  



Mon, 06 Sep 2004 07:58:17 GMT  
 Setfocus during AfterUpdate for a text box
I believe thats what the CausesValidation property and
and the _Validate Event are for...

D.


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 ?



Mon, 06 Sep 2004 09:09:36 GMT  
 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



Mon, 06 Sep 2004 09:27:29 GMT  
 Setfocus during AfterUpdate for a text box
Maybe be as simple as Shift-Tab using Sendkeys before exiting out?

D?


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



Mon, 06 Sep 2004 09:35:36 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. SetFocus and text boxes

2. setfocus to a text box on a tabstrip control

3. How do I add text box during runtime?

4. HELP: Adding text boxes during run time

5. New Text Box during Run-time

6. Text Box during run time

7. How do I add text box during runtime?

8. Text box text on new page text box

9. using VB text boxes data but not text boxes in word 2000

10. Auto popluate text box with data from another text box

11. Columns in List box, when inserting text from text box (VBA)

12. update text box with a timer whilst editing same text box

 

 
Powered by phpBB® Forum Software