Real Software Forums
http://forums.realsoftware.com/

SetFocus, Tab Order problem
http://forums.realsoftware.com/viewtopic.php?f=10&t=47640
Page 1 of 1

Author:  plunkettphoto [ Thu Apr 18, 2013 9:04 pm ]
Post subject:  SetFocus, Tab Order problem

if tfPassword.Text = tfPasswordVerify.Text then
tfFirstName.SetFocus
else
MsgBox("Passwords do not match, reenter")
tfPassword.SetFocus
end


This code is in the LostFocus event of tfPasswordVerify
I have a simple method to test if 2 textfields match in a password test.
tfPassword is tab order 2, tfPasswordVerify is tab order 3 and tfFirstName is tab order 4
when the fields match, everything is fine, no msgbox, and focus goes to tfFirstName.
when the fields don't match, I get the msgbox but focus still goes to tfFirstName instead of going back to tfPassword

What am I doing wrong.

thanks
bill

Author:  timhare [ Thu Apr 18, 2013 10:28 pm ]
Post subject:  Re: SetFocus, Tab Order problem

LostFocus is the wrong place to try to set focus. It gets called before the next field actually gets focus, so what's happening is

tfPasswordVerify LostFocus
tfPassword.SetFocus
tfPassword gets focus
tfPassword loses focus because...
tfFirstName is given focus by the system

As nice as it would be if you could direct traffic from LostFocus, it just doesn't work. Try trapping the tab key in the KeyDown event of each textfield and SetFocus there, before the system initiates focus going to the next control.

Author:  jetpr [ Thu Apr 18, 2013 11:29 pm ]
Post subject:  Re: SetFocus, Tab Order problem

tray FocusNext

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/