Usually, a form processes a text box when a button is clicked. We are adding a button in the form as follows.
Remember to press “Cancel” in the “Command Button Wizard” because we are not using any one of the built-in features.
Next, select the “Event” tab of the button’s property sheet. In the box next to “On Click”, click the drop-down button, then select “Event Procedure”. Press the elipses key (...) to edit the event handler for button click.
Inside the event handler of button click, specify the following code:
This statement echoes the value of the text box in a message box. The subroutine MsgBox takes multiple arguments, of which we only supply the first two. The first argument, Text2.Value refers to the content of the text box Text2. The second argument, vkOKOnly specifies that we only want to present the user with the “OK” button.
Now, go ahead and switch to “Form View’ again. Type some text in the text box, then click the button. A message box should pop up and display the content in the text box.
Note that besides the Value property, a textbox also has a Text property. The difference is that the Text property always reflects the content inside the text box, whereas the Value property reflects what is accepted. The content of a textbox is “accepted” only when the focus is removed from the textbox.