Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Pennsylvania, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Conditional Input Mask (Access 2000,2002)

    Is it possible to set a conditional Input Mask
    I need to store numbers that are stored as text in the following formats

    If there are eleven digits
    7 75867 87654

    If there are twelve digits
    9 87564 74658 0

    if ther are thirteen digits
    8 875645 576874

    if there are fourteen digits
    9 786777 687996 8

    Entering the digits in these formats is easy enough, but you will have that person who will run them together.
    Really messes up a barcode.
    threecrow

    Don't make excuses. It's what you do, not why you didn't.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Conditional Input Mask (Access 2000,2002)

    You can't do this with an input mask; Access doesn't support conditional input masks.
    Instead, you can use in the After Update event of a text box bound to the field in a form. Take out all spaces, then put in spaces at the correct places for the length of the string. Say the text box is named txtField.
    <code>
    Private Sub txtField_AfterUpdate()
    Dim strVal As String
    strVal = Replace(Me.txtField, " ", "")
    Select Case Len(strVal)
    Case 11
    strVal = Left(strVal, 1) & " " & Mid(strVal, 2, 5) & " " & Right(strVal, 5)
    Case 12
    strVal = Left(strVal, 1) & " " & Mid(strVal, 2, 5) & " " & Mid(strVal, 7, 5) & _
    " " & Right(strVal, 1)
    Case 13
    strVal = Left(strVal, 1) & " " & Mid(strVal, 2, 6) & " " & Right(strVal, 6)
    Case 14
    strVal = Left(strVal, 1) & " " & Mid(strVal, 2, 6) & " " & Mid(strVal, 8, 6) & _
    " " & Right(strVal, 1)
    End Select
    Me.txtField = strVal
    End Sub

    Private Sub txtField_BeforeUpdate(Cancel As Integer)
    Dim strVal As String
    strVal = Replace(txtField, " ", "")
    If Len(strVal) < 11 Or Len(strVal) > 14 Then
    MsgBox "Number of digits must be between 11 and 14.", vbExclamation
    Cancel = True
    End If
    End Sub
    </code>
    The Before Update event is used to check the length of the input, and the After Update event to format the string.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Pennsylvania, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Conditional Input Mask (Access 2000,2002)

    Did not think that it was possible,
    Thank you kindly for the code.
    threecrow

    Don&#39;t make excuses. It&#39;s what you do, not why you didn&#39;t.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •