Using (Chr$(13)) to submit data in a TextBox (SOLVED)

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
I tried this and it won't work:

Private Sub TextBox1_Change()
Application.Onkey "{ENTER}" Or "~","Macro1"
End Sub

Basically, after the user enters data into the TextBox and hits the either ENTER key, I want to run Macro1.

What should I do instead?


_________________
Pass on what you have learned. Support this great website by clicking on the sponsor's ads!.
This message was edited by phantom1975 on 2002-08-22 23:38
This message was edited by phantom1975 on 2002-08-23 01:20
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
where is you inputbox called?

Maybe you could make another function that is your own ustom textbox where you have full control of when the user finishes it?
 
Upvote 0
The TextBox is within a UserForm. When the UserForm is activated, the user would input data into the TextBox. Once the user types their data in the TextBox, they will push the ENTER key to submit the data. I can't seem to figure out how to code the ENTER key event.
 
Upvote 0
Sorry, I don't know this one either. Maybe you could use the event TextBox1_Exit(). You would of course get this whenever the cursor leaves the textbox....
 
Upvote 0
Add a command button labeled "submit" to the userform. Set the "default" property of the button to True.

Now when you press the enter key, the click event of the button will be activated (even if the text box has focus at that moment). There you can add Me.Hide, or any other code that you want.
This message was edited by swamp thing on 2002-08-23 00:53
 
Upvote 0
I was trying to get away from having a CommandButton. I know that I can use your code and simply have the CommandButton placed outside of the UserForm width or height. The problem there is that the ENTER key will only work as long as the CommandButton has focus. Once the user starts typing into the TextBox, the TextBox will have focus and the ENTER key will do nothing.
 
Upvote 0
What you say applies when CommandButton.Default is set to False. If it is set to True, then the enter key will trigger the button even when typing into the box (when the box obviously has focus!).

Honest!
This message was edited by Swamp Thing on 2002-08-23 01:01
 
Upvote 0
I tried it, and it seems to activate the code for the CommandButton_Click event as soon as the UserForm is activated. The event I have for the CommandButton_Click is to Unload the UserForm that the CommandButton is located on and Unhide (Show) a different UserForm.

Since I have the CommandButton = True in the UserForm_Initialize event, it seems to click the button as soon as the UserForm is brought up, so it immediately unloads the UserForm as soon as it is activated.
 
Upvote 0
I just found what I am looking for!

Private Sub TextBox1_KeyDown()

If Keycode = 13 Then
Unload Me
UserForm2.Show
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top