Value of text box before it is saved

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SonOf27
    New Member
    • Jul 2008
    • 11

    #1

    Value of text box before it is saved

    I have an unbound text box on an MS ACCESS 2000 form that has an imput mask set for short dates, i.e. 04/11/09. I have some code within the ON_CLICK event of this control that puts the curser at the front, left hand side, of the text box.

    I only want this code to work if there is no value within the text box. It works fine when the textbox is empty and ignors the code as expected if I click on something else after adding a date and then click back into the textbox.

    My problem is the textbox has no value if the user is currently typing something in for the first time. If the user is currently typing a date and wants to click on another part of the date to correct it the cursor is positioned at the front regardless of where the user clicked. Following is the code i'm using in the ON_CLICK event, any help would be appreciated.

    Code:
    If IIf(IsNull(Me.ActiveControl), "", Trim(Me.ActiveControl)) = "" Then
        Me.ActiveControl.SelStart = 0
    End If
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    You can use the textbox.Text property to get the currently contents.

    Comment

    • SonOf27
      New Member
      • Jul 2008
      • 11

      #3
      Many thanks for that ChipR. I guess one should not rely so heavily on autocomplete as Text is not one of the drop down options of ActiveControl but it does work. Thanks again, it works well.

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        The reason it doesn't show up is probably because the property doesn't exist for every possible control that may be the ActiveControl. Be careful using it, you may want to test the type of the control first.

        Comment

        Working...