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

to deactivate the ENTER Key from kexboard

Status
Not open for further replies.

singoi

Technical User
Mar 1, 2005
46
DE
Hallo,

i have a question regarding the Enter key.

i have a few Textboxes where in after entering some values in these Textboxes, and then unexpectedly hitting enter key deletes all the values in text boxes.

i want to deactivate the enter key in run time.

no action even if Enter key pressed should happen.

can anyone please help me.

Singoi
 
Why don't you fix the code that is deleting the text instead? People expect to press Enter to go to the next box
 
Some are used to use TAB button and some ENTER button.

how can i make a code for both using same action.

for what property should i write..

text1_Keypress ?

can you please give me a dummy code for this action Please.

Thanks in Advance

Singoi
 
The first question I would ask is WHY does the enter key erase the text fields. You must have set up a key press event somewhere in the form that will capture it and do something. Modify your code so that it won't do it any more. The only way a key press will do something on a form is if you tell it to.

Once you fix that part, then you can add the keypress events to each field that will pass it to the next tab order.
 
Are you sure that the text is deleted? It is possible that you have multiline text boxes, where enter key adds new line only.

combo
 
in run format i enter all the texts and click enter then all the text boxes are getting cleared.

if i enter two textboxes using tab button and then if i press enter to go to third box..the first two boxes gets cleared.

i dont understand how to deactivate this enter button complately or else use this enter button as tab button.

thank you
 
Well, you keep asking how to deactivate the Enter button, and it's not too hard to do. I'll be glad to tell you how to do it, but I do wish you would listen to the many people who are telling you that you need to get to the bottom of why these deletions are occurring. If you get in the habit of covering over your mistakes with fixes that don't actually fix anything, eventually some of your code will suffer a catastropic collapse, very possibly triggering the same with your professional reputation.

Now, you have written some sort of code, perhaps in a LostFocus event, that is clearing all your text boxes. (VB won't do what you describe without some sort of help from you.) I suggest you find it and fix it.

Although I don't recommend any more than the other responders that you do this, here is how to disable the enter key, since you asked. As you have surmised, you indeed use the keypress event. However, you do not use the text box's keypress event:

1. Set the form's keypreview property to true.
2. In the Form_Keypress event, add the following:
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    KeyAscii = 0
End If
End Sub
Note that if you have set the "Default" property (not the "default property", rather there's a property called default that a number of controls expose) of one of your controls to true (doing this fires the click event of that control when you hit enter), the above will not disable the enter key. Setting the default property takes the enter key out of the list of keys recognized by the keypress event.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top