![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Location: Baltimore
Posts: 29
|
How would I format a textbox to only allow phone #'s? And if the customer enters text the form won't allow them to get to the next form? Here is the code:
intcurrentrow = Sheets("Phone Table").[a65536].End(xlUp).Offset(1).Row On Error GoTo 1: Set mycl2 = Sheet3.Columns("A").Find(What:=txtPhoneNumber.Value) 1: If mycl2 Is Nothing Then Sheets("Phone Table").Range("A" & intcurrentrow).Value = _ txtPhoneNumber.Value Sheets("Phone Table").Range("B" & intcurrentrow).Value = _ TxtAddress.Value End If Me.Hide frmPizzaOptions.Show End Sub |
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
Try something like this for textbox code; Private Sub Textbox1_Change() '// Allow ONLY Numbers '// TextBox number mask Dim Curpos As Double Curpos = TextBox1.SelStart If Not ValidateNumeric(Right(TextBox1.Text, 1)) Then TextBox1.Text = Left(TextBox1.Text, Curpos - 1) End If End Sub Private Function ValidateNumeric(strText As String) As Boolean ValidateNumeric = CBool(strText = "" Or IsNumeric(strText)) End Function |
|
|
|
|
|
|
#3 |
|
New Member
Join Date: May 2002
Location: Baltimore
Posts: 29
|
One problem, I need it to allow the "-" inbetween the numbers such as "410-876-9807"
|
|
|
|
|
|
#4 |
|
New Member
Join Date: May 2002
Location: Baltimore
Posts: 29
|
nevermind, I fixed it. Thanks man
|
|
|
|
|
|
#5 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
How did you fix it? Here is what I came up with. Note this handles the event where the user may enter -- in a row.... Private Sub Textbox1_Change() '// Allow ONLY Numbers '// TextBox number mask Dim Curpos As Double Curpos = TextBox1.SelStart If Curpos = 1 Then '// need to handle -- in a row If Not ValidateNumeric(Right(TextBox1.Text, 1)) Then TextBox1.Text = Left(TextBox1.Text, Curpos - 1) End If Else If Not ValidateNumeric(Right(TextBox1.Text, 1), Mid(TextBox1.Text, Curpos - 1, 1)) Then TextBox1.Text = Left(TextBox1.Text, Curpos - 1) End If End If End Sub Private Function ValidateNumeric(strText As String, Optional strPrev As String) As Boolean ValidateNumeric = CBool(strText = "" Or IsNumeric(strText) _ Or strText = "-" And strPrev <> "-") End Function |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|