Helpful Information
 
 
Category: Visual Basic Programming
Email Validation

am trying to validate an email field. i am putting this in the beforeupdate property of my field:

If IsValidEmail(Me.Personal_Email.Value) Then
MsgBox "Valid Email"
Else
MsgBox "Invalid Email"
End If

then, i am putting this in a module:

Function IsValidEmail(strTextToCheck As String) As Boolean
On Error GoTo ProcErr

Dim bRetVal As Boolean

'Trim spaces
strTextToCheck = Trim(strTextToCheck)

' Check for single @ Symbol
Dim lngPos As Long
Dim strAtSign As String
strAtSign = "@"
lngPos = InStr(1, strTextToCheck, strAtSign, vbTextCompare)
If lngPos > 0 Then ' Found @ sign. Now make sure it's the only one.
lngPos = InStr(lngPos + Len(strAtSign), strTextToCheck, strAtSign, vbTextCompare)
End If

If lngPos = 0 Then
bRetVal = False
Else
' Check for blank space
If InStr(1, strTextToCheck, Chr(32), vbTextCompare) Then
bRetVal = False

Else
' Check for top-level domain
Select Case LCase(Right(strTextToCheck, 5))
Case ".info": bRetVal = True
Case Else
Select Case LCase(Right(strTextToCheck, 4))
Case ".com", ".net", ".biz", ".edu", ".org", ".mil": bRetVal = True
Case Else
Select Case LCase(Right(strTextToCheck, 3))
Case ".tv", ".us", ".cc", ".bz": bRetVal = True
Case Else: bRetVal = False
End Select
End Select
End Select
End If
End If
IsValidEmail = bRetVal

ProcExit:
Exit Function

ProcErr:
ShowErrorMessage ("IsValidEmail()")
Resume ProcExit

End Function


When i run it, am getting message:

Comile Error: Sub or Function not defined. this is referring to the line 'ShowErrorMessage ("IsValidEmail()")

can someone please help?? thanks.

ameen

Do you have this function defined in your project?

isn't it defined in

Function IsValidEmail(strTextToCheck As String) As Boolean
On Error GoTo ProcErr

if i am missing something please tell me. i don't know much about this.

No, you are just calling the function/sub there. Where is the code for the actual function/sub in your project?

if it is not what is called in the beforeupdate property:

If IsValidEmail(Me.Personal_Email.Value) Then
MsgBox "Valid Email"
Else
MsgBox "Invalid Email"
End If

or not the code that i posted in the previous posts then i don't have it. what can i do?? i thought i just need code in the beforeupdate action and module. please help!

ameen










privacy (GDPR)