I want to make my user's data entry easier by simulating an auto tab feature with key strokes so they don't have to use the tab key or mouse when data entry is complete for long text strings such as addresses, cities, email addresses, etc.
Easy Solution:
Note: This is ugly but it will work. I used 2 spaces in the example below. One of the benefits of using spaces is that you don't have to strip them off because the system will do that for you automatically.
Note: For a more generalized (but more complex) treatment or if you want to use something other than 2 spaces, see faq702-2099.
Simplest Case - Delimit with 2 spaces
Step 1: Declare a global variable in the declarations section to hold the data entry string which we will build as the user keys in data. We build a global string because the key events to be trapped only return one character at a time.
******************** Begin Code ********************
Public strSaveUserData As String
********************* End Code *********************
Step 2: Initialize the global string on the Got Focus event of your text based control. We want to start over every time we enter the textbox control.
Note: The same global variable can be used for every text base control on your form since the user can only ever be entering data into one control at a time.
******************** Begin Code ********************
Private Sub ControlName_GotFocus()
strSaveUserData = ""
End Sub
********************* End Code *********************
Step 3: Build and test the global string in the Key Press event of your text based control. This will happen multiple times as the user keys in data. We append the current char to our global string and then check for 2 spaces on the end of the global string. If it finds them, we are done entering data for this field, so we send a tab key to go to the next control on the form.
******************** Begin Code ********************
Private Sub ControlName_KeyPress(KeyAscii As Integer)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.