+ Reply to Thread
Results 1 to 2 of 2

Create a mask inside a textbox

  1. #1
    Forum Contributor
    Join Date
    06-13-2004
    Posts
    120

    Create a mask inside a textbox

    Is there a way to create a mask inside a textbox? I have a form, that will require a Federal Tax ID to be entered in the textbox. And I need it to always have the format of XX-XXXXXXX where X can only be a number 0 through 9...any suggestions??

  2. #2
    Dave Peterson
    Guest

    Re: Create a mask inside a textbox

    Not really.

    But maybe you could just allow numbers and then format it when the user leaves
    the textbox.

    Option Explicit
    Private Sub TextBox1_AfterUpdate()
    With Me.TextBox1
    .Value = Format(.Value, "00-0000000")
    End With
    End Sub
    Private Sub TextBox1_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
    Dim OKChar As Boolean
    OKChar = True
    If Len(Me.TextBox1.Value) >= 9 Then
    OKChar = False
    Else
    Select Case keyascii
    Case Asc("0") To Asc("9")
    'ok
    Case Else
    OKChar = False
    End Select
    End If

    If OKChar = False Then
    keyascii = 0
    Beep
    End If
    End Sub





    dok112 wrote:
    >
    > Is there a way to create a mask inside a textbox? I have a form, that
    > will require a Federal Tax ID to be entered in the textbox. And I need
    > it to always have the format of XX-XXXXXXX where X can only be a number
    > 0 through 9...any suggestions??
    >
    > --
    > dok112
    > ------------------------------------------------------------------------
    > dok112's Profile: http://www.excelforum.com/member.php...o&userid=10581
    > View this thread: http://www.excelforum.com/showthread...hreadid=468341


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1