INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to

Quick and Easy way to Create a Custom Auto Tab feature to speed data entry by SBendBuckeye
Posted: 5 Jul 02 (Edited 6 Jul 02)

Problem to solve:

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)
        
        strSaveUserData = strSaveUserData & Chr$(KeyAscii)
        
        'Send tab key to go to next control if 2 spaces fnd
        If Right(strSaveUserData, 2) = "  " Then
            SendKeys (Chr$(vbKeyTab))
        End If

    End Sub

********************* End Code *********************

If you are using this in several controls on your form, you would want to put the above keypress code in a separate function as below.

************** Alternate Begin Code ****************

    Private Sub ControlName_KeyPress(KeyAscii As Integer)
        
        'Send tab key to go to next control if 2 spaces fnd
        If AllDone(KeyAscii) Then
            SendKeys (Chr$(vbKeyTab))
        End If

    End Sub

    Private Function AllDone(KeyAscii As Integer) As Boolean

        strSaveUserData = strSaveUserData & Chr$(KeyAscii)
        
        'If last 2 = spaces we are done with data entry
        If Right(strSaveUserData, 2) = "  " Then
            AllDone = True
            Exit Function            
        End If

        AllDone = False

    End Function

********************* End Code *********************

Have fun and enjoy!

Back to Microsoft: Access Forms FAQ Index
Back to Microsoft: Access Forms Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close