Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Set Data Entry to Begin at the Far Left or Far Right of a Control That Has an Input Mask


View products that this article applies to.

This article was previously published under Q268102
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

↑ Back to the top


Summary

In a form, if a control has an input mask, you can enter data into any position in the control (left, right, middle), even if you first click in the control. There is no option that you can use to turn this feature off. This article shows you how to use code to set data entry to begin at either the right or the left side when you enter a control.

↑ Back to the top


More information

To see a demonstration of how to set data entry to begin at either the right or the left side when you enter a control that has an input mask, follow these steps:
  1. In a new Microsoft Access database, create a form that is not based on any table or query with the following specifications:
       Form: Test1
       -----------------
       Caption: TestForm
    
       Text box
       ------------
       Name: Field1
       
       Text box
       --------------------------
       Name: MyDate
       Input Mask: 99/99/0000;0;_
    					
  2. View the form in Form view, and then click in the middle of the MyDate control. Note that the mouse pointer appears where you clicked, instead of at the beginning or end of the control.
  3. Switch back to Design view of the form, and on the View menu, click Code. Type or paste the following code:
    Option Compare Database
    Public stayPut As Boolean
    
    'On each record set stayPut to False
    Private Sub Form_Current()
        stayPut = False
    End Sub
    
    Private Sub myDate_Click()
        setStart
    End Sub
    
    Private Sub myDate_DblClick(Cancel As Integer)
        setStart
    End Sub
    
    Sub setStart()
    Dim x As Variant
    Dim intWait As Integer
    
    'Important: You may need to increase or decrease the value of
    'intWait to have it work smoothly on your system.
    
    intWait = 200
    
    'If stayPut is false, wait, then send keystroke for the Home key.
    'This moves the cursor to the beginning of the field.
    
        If stayPut = False Then
            For i = 1 To intWait
                x = DoEvents
            Next i
    
    'Note: To have the cursor move to the far right,
    'replace "{Home}" with "{End}".
    
            SendKeys "{Home}"
    
    'Next, stayPut is set to True in case you want to select
    'a portion of the field after getting inside it.
    
            stayPut = True
        End If
    End Sub
    
    
    Private Sub myDate_LostFocus()
    'Once you are out of the field, stayPut is set back to False so
    'the setStart procedure will run the next time the field is clicked.
    
        stayPut = False
    End Sub
    					
  4. Close the Visual Basic Editor, and then save the form.
  5. View the form in Form view again, and then click anywhere in the MyDate control. Note that the mouse pointer moves to the far left of the control.

↑ Back to the top


Keywords: KB268102, kbhowto

↑ Back to the top

Article Info
Article ID : 268102
Revision : 4
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 272