Reject Entry

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a field on my form call email address.

As part of the entry for this field I want to reject certain domains (e.g.
@hotmail.com, @yahoo.com, etc).

The ideal situation would be for me to have a table that I can list of the
domains to reject and then have some function or code to inspect the entry to
see if the entry contains one of the invalid domains. But I need to find out
if there is some vb code I can use to solve this or a function that can be
used.

Thanks for any help.
 
Assuming you've got a table that contains the domains, you can use a
function such as the following to determine whether or not the current
e-mail address is to be rejected:

Function ValidDomain(EMailAddress As String) As Boolean

Dim intAt As Integer
Dim strDomain As String

intAt = InStr(1, EMailAddress, "@")
If intAt > 0 Then
strDomain = Trim$(Mid$(EMailAddress, intAt))
ValidDomain = (DCount("*", "Domains", "Domain = '" & strDomain & "'")
= 0)
Else
ValidDomain = False
End If

Exit Function

(This assumes your invalid domains are stored in a table named Domains, that
there's a field Domain in that table, and that Domain includes the @
character: @hotmail.com, @yahoo.com, etc)
 
Back
Top