I'm using a function that allows me to review a string of text and evaluate if it is composed of letters. It is housed in a module called "General". The general module only exists to house public functions and variables. Function code is listed below:
Public Function IsAlpha(strValue As String) As Boolean
Dim intPos As Integer
For intPos = 1 To Len(strValue)
Select Case Asc(Mid(strValue, intPos, 1))
Case 65 To 90, 97 To 122
IsLetter = True
Case Else
IsLetter = False
Exit For
End Select
Next
End Function
Next I have two "if" routines that evaluate the first 2 characters of a textbox in my userform. The first routine asks if the 1st character is numeric and the second routine asks if the 2nd character is alpha. Currently, the second "if" routine is ejecting me from the sub-routine when IsAlpha tests True, rather than generating the MsgBox. Is the IsAlpha function not being called correctly?
If routines code listed below:
Private Sub CmdMap_Click()
With TxtDxCode
If IsNumeric(Left(Me.TxtDxCode.Text, 1)) Then
MsgBox "Incorrect DX Code format was entered. ", vbExclamation, "DX Code Entry"
TxtDxCode.Value = ""
TxtDxCode.SetFocus
Exit Sub
End If
If IsAlpha(Left(Me.TxtDxCode.Text, 2)) Then
MsgBox "Incorrect DX Code format was entered. ", vbExclamation, "DX Code Entry"
TxtDxCode.Value = ""
TxtDxCode.SetFocus
Exit Sub
End If
End With
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…