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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem whit .setfocus

Status
Not open for further replies.

Mollethewizard

IS-IT--Management
Nov 18, 2002
93
SE
I have got a major problem whit a user form.

The form has 4 textboxes a command button and a number of labels.

When the form is initialized the 4th textbox is set - visible = False. If the textbox preceding has a value of 13 then the textbox is visible from code in the exit-event of the third textbox.

The problem is that the focus jumps to the command button in spite that the tab-order in the form is correctly set.

I suppose that I can force the set focus in some event (I hope!) but in which event and in which text box and finally how to code?

Can anybody help?

Christer
 
Try the AfterUpdate event procedure of the 3rd textbox.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PH it didn’t work.

Maybe it’s the .setfocus command that can’t be called inside a textbox or something like that?!

Is there a description in which order the events execute? I understand that the textbox must be visible so that the .setfocus command can bite.

Christer
 
PH it didn’t work
It's quite vague ...
What have you tried ?
Setting the .Visible property and calling the .SetFocus method doesn't work in the AfterUpdate event procedure of the 3rd textbox ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PH – thanks for trying to help. I will return to my problem a little later when I got the time to explain what I have done and what I want the macro to accomplish.

Christer
 
Actually, I suspect your code works fine, but you're overlooking the order of events. The Exit event occurs after AfterUpdate, and Exit is where your focus is shifted to the next control. So your SetFocus is working just fine-- but it's setting the focus on the textbox that already has the focus, and then your application moves on to the Exit event where your focus is shifted.

One of the nice aspects of the Exit event is that you can use the Cancel command (it's not an option for AfterUpdate). SetFocus won't stop a user from clicking directly on the command button with invalid data in your textbox, but Cancel will undo whatever action caused the event (Exit) to fire-- be it a mouse click, a tab-key entry, or whatever.
 
Rakafkaven welcome to the forum! I’m very pleased that I was the first to get a tip for a solution from you! I will test your tip when I get time for “problem solution”.

Christer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top