Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetFocus from OnExit event

Status
Not open for further replies.

LARiot

Programmer
Feb 7, 2007
232
Hi. Thanks for looking into this.

As with any thread, please only reply after reading carefully. Also only if you are sure of the correct answer. No one likes to read a bunch useless posts before getting to the right answer. Especially when they have to read more than one post.

In the OnExit event of a text box I have the following:
Code:
Me.txtJobNumber.SetFocus

However, the following textbox gets the focus when the user tabs to another control. What's probably happening is that the txtJobNumber does get the focus then vba goes back to what it was going to do and changes the focus to the next control on tab index sequence.

How do I set the focus back to txtJobNumber from it's own event?

-Nima
"Pluralitas non est ponenda sine necessitate", i.e., "Plurality is not to be posited without necessity" aka K.I.S.S. (Keep It Short and Simple) -- Ockham's Razor
 
Please forgive me if you find the beginning of my previous post offensive. I have made the mistake myself in the past.

-Nima
"Pluralitas non est ponenda sine necessitate", i.e., "Plurality is not to be posited without necessity" aka K.I.S.S. (Keep It Short and Simple) -- Ockham's Razor
 
I cannot replicate this but my first thought would be to add doevents prior to setting the focus. That way it would finish processing any other cached events before setting the focus. Sorry if this is an incorrect "useless post" and wasted your valuable time.
 
Why are you returning Focus to the Control that just lost it? The most common reason for doing this is that something has gone awry, such as a Validation failing because incorrect data was entered. This type of thing is usually checked in the Control's BeforeUpdate event, and the Focus will remain in the Control, using this event, if you Cancel the Update by using

Cancel = True

Linq ;0)>

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
MajP: Thanks for your response. You are certainly not wasting my time.

Perhaps it was unwise of me say "useless".

-Nima
"Pluralitas non est ponenda sine necessitate", i.e., "Plurality is not to be posited without necessity" aka K.I.S.S. (Keep It Short and Simple) -- Ockham's Razor
 
>I cannot replicate this

I can - and I second missinglinq's suggestion of simply cancelling the Exit event to avoid the issue
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top