Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code for E-mail field

Status
Not open for further replies.

LeiDBug007

Technical User
Oct 15, 2003
33
US
Greetings all,

We're trying to set-up a code for an E-mail field where the user cannot leave the field unless they place the "@" symbol. Then, have a msg box that indicates that the e-mail is invalid and it locks them in that field until they correct the e-mail address.

I'll probably have to set-up the same string for the ".com" as well.

Everyone's expertise is much needed!!!

Thanx so much! ;-p
 
You previously posted this under thread181-720124. Several people, including myself, were giving help in that thread. Why the change???

****************************
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Dear mstrmage1768,

Sorry but we tried the codes suggested and it would not work properly. I kept getting error messages (?). We thought it was just the system getting tired yesterday, but we launched that code all over again from scratch and still no go(!?).

I just truly need a code to flag the users on the "@" and the ".com" on the e-mail field.

Help... {8-()
 
if you want to send an email to my work addy and let me know what version of acces you are running I will send you a working sample that does what you are asking....

****************************
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
not sure where I got this code from (possibly here a long time ago) credit to the original poster :)

add this code to the 'on exit' event of your text field (change names as appropriate):


Private Sub Email1_Exit(Cancel As Integer)
Dim bLen As Boolean 'length of email address must be at least 6
Dim bA As Boolean 'must contain the @ symbol
Dim bP As Boolean 'must contain the . symbol
bLen = True 'We assume all are conditions are met to start
bA = True
bP = True

'Return false if any criteria is not met.
If Len(Email1) < 6 Then bLen = False
If InStr(1, Email1, &quot;@&quot;) = 0 Then bA = False
If InStr(1, Email1, &quot;.&quot;) = 0 Then bP = False

'If there are mistakes go to Validate else finished.
If bLen = False Or bA = False Or bP = False Then
GoTo Validate
Else
Exit Sub
End If

'Show the user his mistakes
Validate:

Dim LengthWarning As String
Dim AWarning As String
Dim PWarning As String

If bLen = False Then
LengthWarning = &quot;> You must have at least 6 characters. You only typed &quot; & Len(Email1)
Else
LengthWarning = &quot;> Length = OK&quot;
End If

If bA = False Then
AWarning = &quot;> You are missing the '@'symbol.&quot;
Else
AWarning = &quot;> '@' symbol = OK&quot;
End If

If bP = False Then
PWarning = &quot;> You are missing the '.' symbol.&quot;
Else
PWarning = &quot;> '.' symbol = OK&quot;
End If

MsgBox &quot;The email address you entered is not valid.&quot; _
& vbNewLine & LengthWarning & vbNewLine & AWarning & vbNewLine _
& PWarning, vbCritical + vbOKOnly, &quot;oi Chump ~ Validation Error&quot;
DoCmd.CancelEvent
Email1.SetFocus
End Sub

____________________________________
Eat [pc3], Sleep [pc3], Live [pc3]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top