Return True Locks Textbook When Trying To Stop Beep

Hi,

I have several text boxes that the user navigate to by hitting the enter button. I use the following code which works great, except you sometimes get a beep.

if Key = chr(3) or Key = chr(13) then TextField2.SetFocus end if

So, to fix this you are suppose to add the Return True statement:

if Key = chr(3) or Key = chr(13) then TextField2.SetFocus end if Return True

What happens now is that the text box is locked and you can’t type anything into it. You remove the Return True line and it works again. The original reference for the beep problem was at:

https://forum.xojo.com/10170-beep-when-enter-is-pressed

What am I doing wrong?

Jim

[quote=94115:@James Redway]Hi,

I have several text boxes that the user navigate to by hitting the enter button. I use the following code which works great, except you sometimes get a beep.

if Key = chr(3) or Key = chr(13) then TextField2.SetFocus end if

So, to fix this you are suppose to add the Return True statement:

if Key = chr(3) or Key = chr(13) then TextField2.SetFocus end if Return True

What happens now is that the text box is locked and you can’t type anything into it. You remove the Return True line and it works again. The original reference for the beep problem was at:

https://forum.xojo.com/10170-beep-when-enter-is-pressed

What am I doing wrong?

Jim[/quote]

You should return true only when you got the return or enter key. Otherwise you kill all keys :

if Key = chr(3) or Key = chr(13) then TextField2.SetFocus Return True end if

By placing the Return True outside of the IF conditional, you are returning true no matter what key is entered and, thus, preventing all entry. Put the return true INSIDE the if statement.

Damn, too late again. :slight_smile:

If you want Enter/Return to do what the Tab key does, you should use the FocusNext method:
Window.FocusNext

If key = Chr(3) Or key = Chr(13) Then FocusNext() Return True End

Wow! Wicked fast for a Sunday morning. Thanks so much to all for your help. I really appreciate it.

Jim

The first question is 7 years which I have been able to answer - and everyone else beat me to it!!! :frowning:

Only counts the good will. Congratulations for being willing to share :slight_smile: