how to set "enter" ?

i has i text box.
i want the user write some text on it and after that press the enter key.

the problem is how ? and whats the code ?

thank.
JOHNHOAsked:
Who is Participating?
 
alokanantConnect With a Mentor Commented:
u can use the following code in the key press event of the text box -

if (keyascii = vbkeyreturn) then\
   sendkeys "{TAB}"
end if

i think u want that when the user presses enter the focus should shift to the next control.

hope this helps.

alok
0
 
JOHNHOAuthor Commented:
i havent try the code yet.
for your information.
i want the user write a text into that text box.
and after that press the enter key.

the system will perform the thing that user has enter the text in the text box.
like show form or perfoem function.

i hope u inderstand what i mean.
thanks.
0
 
JOHNHOAuthor Commented:
i has use your code.
i put the hole code in the text box()text1_change )status.
but why nothing happend ?

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
KDivadCommented:
I think you want something like:

Sub Text1_KeyPress(KeyAscii As Integer)

If Not KeyAscii = 13 Then Exit Sub
KeyAscii = 0 ' Use if you don't want the enter key
' doing anythiing else
Select Case LCase$(Text1.Text)
Case "show form"
    Form1.Show
Case "hide form"
    Form1.Hide
Case "open notepad"
    x = Shell("C:\Windows\Notepad.exe")
...'Enter other
...'possibilities
...'here
Case Else
    MsgBox "Unrecognized command"
    Text1.SelStart = 0
    Text1.SelLength = Len(Text1.Text)
End Select

End Sub

Hope this helps!
0
 
JOHNHOAuthor Commented:
thanks, i can do it now !!

but how about instead of using "enter" key , now i want to using "F3" key.
whats the code ?

and can u give me the details so next time i no need to bother you again,
lets say instead of using "enter","F3" , how about the other key word like "a" ,"b"
or "c".
please explain for me more details in learning to put the key
thanks.

0
 
JOHNHOAuthor Commented:
btw, what
If Not KeyAscii = 13 Then Exit Sub
      KeyAscii = 0 ' Use if you don't want the enter key

keyascii= 13 mean ?
keyascii= 0 mean ?

please explain more detail for me if i want to put the other function instead of "enter"
?
thanks
0
 
KDivadCommented:
Replace the code I gave you with this one, because the code I gave you won't work with the "F" keys (F1, F2, ... F12).

Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)

If Not KeyCode = 13 Then Exit Sub
KeyCode = 0 ' Use if you don't want the key
' doing anythiing else
Select Case LCase$(Text1.Text)
Case "show form"
    Form1.Show
Case "hide form"
    Form1.Hide
Case "open notepad"
    x = Shell("C:\Windows\Notepad.exe")
...'Enter other
...'possibilities
...'here
Case Else
    MsgBox "Unrecognized command"
    Text1.SelStart = 0
    Text1.SelLength = Len(Text1.Text)
End Select

End Sub

I would suggest replacing "KeyCode = 13" with "KeyCode = vbKeyReturn". For a complete list of the built in keycode constants, check the vb help file and search for "keycode". That list in the help file will contain a list of KeyCode constants for each and every key. One note, however, use "KeyCode = vbKeyA" for "a" and "KeyCode = vbKeyA And Shift = vbShiftMask" for "A".

Need any more help, just holler.
0
 
JOHNHOAuthor Commented:
i still not understand, and i already your second code, but nothing happend.

can you give complete code by using F3 ? after that i will know what you mean ,
thanks.

0
 
JOHNHOAuthor Commented:
plus information,
i has put
keyascii=114 (should be F3 key)

but why nothing happend when the time i press F3 key ?

is there something faults ?

i still not understaqnd, also when the time i press "a" , my text box just show me "a" word, even i already put keyascii=65 , what actually is happend ?

thanks.
0
 
JOHNHOAuthor Commented:
YES I CAN DO IT !!!
thanks a lot.

but 1 more thing still not understand.

i want to has 3 key codes.

1 is for my user to enter one job (thats is enter key)
1 is for my user to F3 to perform the other job
1 is for my user to press "a" botton to perform the other job.

how can i do it in 1 form,

confuse already.

thanks

0
 
KDivadCommented:
Make sure you are using the KeyUp event and not the KeyPress event. Also, make sure you use KeyCode and not KeyAscii.

Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
Case vbKeyReturn
    'Enter key was pressed, so execute first job
Case vbKeyF3
    'F3 key pressed, execute second job
Case vbKeyA
    '"a" key was pressed, execute third job
End Select

End Sub
0
 
JOHNHOAuthor Commented:
WOW YOU REALLY HELP ME THIS TIME !!!
thanks a lot friend.

please answer my new question.
thanks

0
 
KDivadCommented:
No problem, though you did accept the wrong person's answer.
0
 
alokanantCommented:
for kdavid,

is there a way to transfer the points to you?

alok
0
 
KDivadCommented:
Alokanant,

If I remember correctly, they can add points to my account but the only way to remove points from yours is to delete your account and have you start a new one. So call it an early/late birthday present and we can just leave it like that, ok? I don't play for the points anyway, so I don't really miss them.

Happy B-Day :-)
KDivad
0
 
JOHNHOAuthor Commented:
to kdavid ,
sorry because i has enter the wrong account.

how do you show me the way to transfer the points ?
or you can help me to answer my new question and i will increase the miss points that i didnt give it to you.
the question is in the new question section , please go there.

my question is , how do we block some person from presing some botton, assume it is F4 key ?
thanks , please go there. i m waiting for you.

thanks
0
 
KDivadCommented:
You can't transfer the points.

I'll look at your question.
0
All Courses

From novice to tech pro — start learning today.