Hello,
I have a text box and a command button, what is the code to make sure that the text of the text box is not a number when I click the command button?
Printable View
Hello,
I have a text box and a command button, what is the code to make sure that the text of the text box is not a number when I click the command button?
VB Code:
Private Sub Command1_Click() If IsNumeric(Text1.Text) = True Then Exit Sub End If End Sub
This might be what you are looking for.
This will work if the number is greater than 0 only.
VB Code:
Private Sub Command1_Click() If Val(Text1.Text) > 0 Then MsgBox "Valid Number" End If End Sub
This will find a number anywhere within the textbox string.VB Code:
Private Sub Command1_Click() Dim EachCharacter As String * 1 Dim MyNumber As Integer Dim i As Long For i = 1 To Len(Text1.Text) EachCharacter = Mid(Text1.Text, i, 1) If IsNumeric(EachCharacter) Then 'its a number MsgBox "No numbers allowed" Exit For End If Next End Sub