web development India freelance website designer
Description:This code turns a standard textbox into a masked textbox
which only accepts social security numbers and places dashes
accordingly.
Assumes:Create a textbox and name it txtSSN. Paste the code in the form.

Private Sub txtssn_Change()
Dim strTemp As String
Dim intPos As Integer
Dim intSel As Integer
Dim intLen As Integer
With txtssn
intSel = .SelStart
intLen = Len(.Text)
strTemp = .Text
intPos = InStr(1, strTemp, "-")
While intPos <> 0
strTemp = Left(strTemp, intPos - 1) & Right(strTemp, Len(strTemp) - intPos)
intPos = InStr(1, strTemp, "-")
Wend
If Len(strTemp) > 2 Then
strTemp = Left(strTemp, 3) & "-" & Right(strTemp, Len(strTemp) - 3)
If Len(strTemp) > 5 Then strTemp = Left(strTemp, 6) & "-" & Right(strTemp, Len(strTemp) - 6)
End If
.Text = strTemp
intSel = intSel + (Len(.Text) - intLen)
If intSel < 0 Then intSel = 0
.SelStart = intSel
End With
End Sub

Private Sub txtssn_KeyPress(KeyAscii As Integer)
Dim intSel As Integer
With txtssn
If KeyAscii >= 48 And KeyAscii <= 57 Then
If Len(.Text) >= 11 Then KeyAscii = 0
ElseIf KeyAscii = 8 Then
KeyAscii = 0
intSel = .SelStart
If intSel = 4 Or intSel = 7 Then
.Text = Left(.Text, intSel - 2) & Right(.Text, Len(.Text) - intSel)
.SelStart = intSel - 2
ElseIf intSel > 0 Then
.Text = Left(.Text, intSel - 1) & Right(.Text, Len(.Text) - intSel)
.SelStart = intSel - 1
End If
Else
KeyAscii = 0
End If
End With
End Sub
Create a Social Security Number Textbox

1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550

Freelance ASP PHP web development | Web developer India Web development India| Prayagasoft - web designer India, Ecommerce developer india, Ecommerce design