Input Mask?

  • I'm sure this will be easy for an Access person.  I have a form with field "Lastname".  The users want the FIRST letter capitalized and the rest of the letters to be user optional.  This is so names like McBride can be entered properly.  The example I keep finding on the internet >L<????????????, of course, doesn't allow this.

    Can anyone tell me how to do this?

  • I can't see a way to do this, there is no character that 'turns off' the force upper or lower case within the mask specification.

    Perhaps an alternative is to use the BeforeUpdate event to force the first character to be upper case???

  • I couldn't find a way to do this via an input mask so I just wrote a string maniplulation function to deal with these fields plus a couple of others.

    Thanks for the response. RH

  • Private Sub LastName_AfterUpdate()

    Dim myString As String

    myString = UCase(Mid(Me.LastName, 1, 1)) & Mid(Me.LastName, 2, Len(Me.LastName))

    Me.LastName = myString

    End Sub

  • Private Sub LastName_BeforeUpdate()

      Me.LastName = UCase(Left(Me.LastName, 1)) & Mid(Me.LastName, 2)

    End Sub

    It is better to use the BeforeUpdate event, as this is something you want as part of the actual update, not something to be updated again.  Two other small picks:  Using Left with a length of 1 rather than Mid starting at 1 for 1 is more to the point, and then using Mid starting at 2 with no length for the remainder of LastName saves calculating the length (Len) which is used wrong anyway.  If you are going to calculate the length, then starting at 2 you need to subtract 1.  But no need to bother, as the Mid function just uses the remainder of the string when no length is given.

     

     

    [font="Comic Sans MS"]Vic[/font]
    www.vicrauch.com

  • try this on your change event (where Text0 is the name of your input box)

    Option Compare Database

    Dim InChange As Boolean

    Private Sub Text0_Change()

        Dim pS As Integer

        Dim pL As Integer

        If InChange Then Exit Sub

       

        InChange = True

        pS = Text0.SelStart

        pL = Text0.SelLength

        Debug.Print pS & ", " & pL & ", '" & Text0.Text & "'"

        If Len(Text0.Text) = 1 Then

            Text0.Text = UCase(Text0.Text)

        End If

        Text0.SelStart = pS

        Text0.SelLength = pL

         InChange = False

    End Sub

    ---------------------------

    Ric

     

     

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply