Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / March 2007

Tip: Looking for answers? Try searching our database.

Validation Rule

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fishmiester - 28 Mar 2007 02:14 GMT
Hi,
I am an access novice and would like to create a validation rule for an
email address in Access 2000.

Is there any one out there that could help me??

Your assistance is greatly appreciated.

Fish
Allen Browne - 28 Mar 2007 11:29 GMT
Try:
   Is Null OR ((Like "*?@?*.?*") AND (Not Like "*[ ,;]*"))

Explanation:
   http://allenbrowne.com/ValidationRule.html

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Hi,
> I am an access novice and would like to create a validation rule for an
[quoted text clipped - 5 lines]
>
> Fish
Jamie Collins - 28 Mar 2007 15:07 GMT
On Mar 28, 11:29 am, "Allen Browne" <AllenBro...@SeeSig.Invalid>
wrote:
> > I am an access novice and would like to create avalidationrule for an
> > email address in Access 2000.
>
> Try:
>     Is Null OR ((Like "*?@?*.?*") AND (Not Like "*[ ,;]*"))

I think being ANSI mode neutral is a good thing (e.g. to enforce data
rules for both ADO and DAO) and the validation could be a little more
involved e.g.

([email_address] LIKE '%_@_%._%' OR [email_address] LIKE '*?@?*.?*')
AND [email_address] <> '%_@_%._%'
AND [email_address] <> '*?@?*.?*'
AND [email_address] NOT LIKE '%[!0-9A-Z''._@-]%'
AND [email_address] NOT LIKE '*[!0-9A-Z''._@-]*'
AND LEN(MID([email_address], 1, INSTR(1, [email_address], '@') - 1))
BETWEEN 1 AND 127
AND LEN(MID([email_address], INSTR(1, [email_address], '@') + 1))
BETWEEN 1 AND 127
AND INSTR(INSTR(1, [email_address], '@') + 1, [email_address], '@') =
0

Actually, rather than having one big Validation Rule, I'd have several
smaller rules implemented as CHECK constraints, each with a meaningful
name that would appear in the error description, to be able to give
more meaningful feedback to the user e.g.

Sub ValidateEmail()
' Kill Environ$("temp") & "\DropMe.mdb"
Dim cat
Set cat = CreateObject("ADOX.Catalog")
With cat
 .Create _
     "Provider=Microsoft.Jet.OLEDB.4.0;" & _
     "Data Source=" & _
     Environ$("temp") & "\DropMe.mdb"
 With .ActiveConnection
   .Execute _
   "CREATE TABLE Test ( " & vbCr & "email_address" & _
   " VARCHAR(255) NOT NULL, " & vbCr & "CONSTRAINT" & _
   " email__basic_pattern" & vbCr & "CHECK (" & vbCr & _
   " (email_address" & _
   " LIKE '%_@_%._%' OR email_address" & _
   " LIKE '*?@?*.?*') " & vbCr & "AND email_address" & _
   " <> '%_@_%._%' " & vbCr & "AND email_address" & _
   " <> '*?@?*.?*'" & vbCr & "), " & vbCr & "CONSTRAINT" & _
   " email__legal_characters" & vbCr & "CHECK" & _
   " (" & vbCr & "email_address NOT LIKE '%[!0-9A-Z''._@-]%'" & _
   " " & vbCr & "AND email_address NOT LIKE" & _
   " '*[!0-9A-Z''._@-]*'" & vbCr & ")," & _
   " " & vbCr & "CONSTRAINT email__mailbox_name_length" & vbCr & _
   " CHECK (" & vbCr & "LEN(MID(email_address, 1, INSTR(1," & _
   " email_address, '@') - 1)) BETWEEN" & _
   " 1 AND 127" & vbCr & ")," & vbCr & _
   " CONSTRAINT email__domain_name_length" & vbCr & "CHECK" & _
   " (" & vbCr & "LEN(MID(email_address, INSTR(1," & _
   " email_address, '@') + 1)) BETWEEN" & _
   " 1 AND 127" & vbCr & ")," & vbCr & _
   " CONSTRAINT email__one_commerical_at" & vbCr & "CHECK" & _
   " (" & vbCr & "INSTR(INSTR(1, email_address," & _
   " '@') + 1, email_address, '@')" & _
   " = 0" & vbCr & ")" & vbCr & ");"

   On Error Resume Next
   ' Try adding illegal value (two @'s)
   .Execute _
   "INSERT INTO Test (email_address) VALUES ('a@b.c@m');"
   If InStr(Err.Description, "email__one_commerical_at") > 0 Then
     MsgBox "A valid email may only have one '@' character."
   End If
   On Error GoTo 0
 End With
 Set .ActiveConnection = Nothing
End With
End Sub

Jamie.

--
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.