Normal Topic ThrowFocus not working as I expect. (Read 786 times)
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
ThrowFocus not working as I expect.
Apr 12th, 2012 at 9:10pm
Print Post Print Post  
I'm trying to set up a command button that will check the element EmployeeName to see if it is empty or if the number exists in another database.  If the element is blank or the number doesn't exist, I want to have a message box appear to give direction and then set the cursor in the EmployeeName element.

The programming is below and works through the appearance of the proper message box, however the cursor moves on to the next element rather than returning to the EmployeeName element.  I'm trying to do it via the ThrowFocus command.

Any thoughts on why this isn't working?


var vName as string
var vReturnVal as string
var vName2 as string

If @IsBlank(EmployeeNumber)
     {
           @MsgBox("PLEASE ENTER YOUR EMPLOYEE NUMBER AND THEN PRESS ENTER","","")
           ThrowFocus(EmployeeNumber)
     }      
Else
     {

           vReturnVal = @XLookupSourceList(@Fn, EmployeeNumber, "employee!Empl#", "First Name;Last Name")

           vName=@AccessStringArray(vReturnVal,1)
           vName2=@AccessStringArray(vReturnVal,2)

           FirstName=vName
           LastName=vName2

           Name=firstname+" "+LastName

           ThrowFocus(NameIsCorrect)
     

                 If @IsBlank(Name)
                 {
                       @MsgBox("THAT EMPLOYEE NUMBER IS NOT AVAILABLE.","","PLEASE SEE YOUR SUPERVISOR OR HR MANAGER")
                       EmployeeNumber=""
                       ThrowFocus(EmployeeNumber)


                 }
                 Else
                 {
                 Visibility(NameIsCorrect,1)
                 Visibility(NameIsNOTCorrect,1)
                 }
     }

  
Back to top
 
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: ThrowFocus not working as I expect.
Reply #1 - Apr 13th, 2012 at 6:14pm
Print Post Print Post  
my experience early on was that Sesame doesn't like  @Msgbox() and Throwfocus in the same {section}.   

Here is a comment from Hammer back in 2009 on this topic:

"@MsgBox tries very hard to put focus back in the element where you were when it pops up after the message is dismissed. This appears to be fighting with ThrowFocus trying to force focus to go elsewhere."

Maybe an inelegant workaround would be to have two throwfocus commands - the first one to throwfocus to the originating element from which @MsgBox popped (to satisfy @MsgBox's desire to return to the originating element) and then the second ThrowFocus to jump to the element where YOU want the focus to end up ?
  

Larry
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: ThrowFocus not working as I expect.
Reply #2 - Apr 13th, 2012 at 6:54pm
Print Post Print Post  
You say you want it to go to EmployeeName, but your code does not contain a ThrowFocus with that LE in it.

Also, it appears that you are trying to throw focus to NameIsCorrect before it is visible. I haven't tested it, but I would suspect that Sesame cannot put focus in a layout element that is hidden.

And, just to verify the interaction between @MsgBox and ThrowFocus, I pasted your code into a command button in the Customers sample app, changed the LE references, and it seemed to properly put focus into the desire LE after I clicked OK to dismiss the MsgBox.

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: ThrowFocus not working as I expect.
Reply #3 - Apr 16th, 2012 at 3:22pm
Print Post Print Post  
Sorry, I miss spoke when I said I was trying to set the focus to EmployeeName.  I meant EmployeeNumber.

I've tried everything I can think of and it still doesn't work.

I tried removing all the programming except for the command ThrowFocus(EmployeeNumber) in the Employee element On Element Exit.  This should have kept me in the EmployeeNumber element until I entered something, however, it behaved as if there is no command there.

If I replaced the EmployeeNumber in the ThowFocus command to some other element on the form, it would behave as expected!!

Help!
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: ThrowFocus not working as I expect.
Reply #4 - Apr 16th, 2012 at 6:19pm
Print Post Print Post  
NHUser wrote on Apr 16th, 2012 at 3:22pm:
I tried removing all the programming except for the command ThrowFocus(EmployeeNumber) in the Employee element On Element Exit.


I thought you were trying to run this code from a command button because your first message began with "I'm trying to set up a command button...", but now I see that you have this code in the On Element Exit event of what, the EmployeeNumber? If that's the case, you will have issues trying to make Sesame display a MsgBox, and attempt to put focus back into the element which called the MsgBox.

One solution is to put the code in the On Element Entry event of the next LE. This will work because Sesame will normally be able to send focus to another LE, even if you display a MsgBox.

Let me know if that helps.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: ThrowFocus not working as I expect.
Reply #5 - Apr 16th, 2012 at 7:29pm
Print Post Print Post  
Again, sorry for the confusion.  I started out with a command button, but then I tried to make it part of the programming without using a command button.

I was able to get it to work by using your recommendation to use the On Element Entry event for the next LE.

Thanks for your help!
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: ThrowFocus not working as I expect.
Reply #6 - Apr 17th, 2012 at 1:52am
Print Post Print Post  
Your welcome. Glad to hear that it worked.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged