Results 1 to 5 of 5

VBA inputmask

  1. #1
    erandalln is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    3

    VBA inputmask

    I am trying to write an input mask that displays one mask if the entire field is filled and another if it is filled in a specific partial of the whole. In the case of an American zip(+4), "12345", if 5 digit characters are entered and "12345-6789", if 9 digit characters are entered; in the case of phone number, the variants are: "123.456.7890", if area code is included, "123.4567", if no area code, "123.4567 x123...", if extension is included, and "123.456.7890 x12...", if both are included. Note that just the digit characters are stored, and the punctuation characters are not.



    My problem: The zip code field is recreating and locking an actual input mask, based on the initial value of the opening record every time I run form view.

    Code:
    Option Compare Database
    
    Private Sub ContactPhone_LostFocus()
        If Len(Me.ContactPhone) > 7 Then
            Me.ContactPhone.InputMask = "999\.000\.0000;;"
        Else
            Me.ContactPhone.InputMask = "000\.0000;;"
        End If
    End Sub
    
    Private Sub Zip_LostFocus()
        If Len(Me.Zip) > 5 Then
            Me.Zip.InputMask = "00000\-9999;;_"
        Else
            Me.Zip.InputMask = "00000;;_"
        End If
    End Sub
    Any help/leads would be greatly appreciated. I don't want to tell the client "sorry, you can have professional-looking, effective, or easy-to-use, but not any combination of the above."

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,047
    Your if Len( )>7 picks up both numbers as len(123.4567) = 8 which is >7

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    2,898
    The point of using Input Masks is to ensure that data is entered correctly...what's the point in setting it after the data has been entered?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    erandalln is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    3
    Is there a "display mask" of some sort for form view and datasheet view? That would solve all of the formatting issues I've discovered.

  5. #5
    erandalln is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2017
    Posts
    3
    If I test for the length of the zip code field, how (where?) do I put the test condition into the Conditional Formatting wizard? I just found that feature.

    Edit: And then, where do I tell it how to format the field display--my exploration hasn't turned that up yet.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 07-15-2012, 01:48 PM
  2. InputMask yyyy-mm for Label
    By smaky in forum Queries
    Replies: 5
    Last Post: 11-03-2010, 10:20 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums