[mso] Re: Excel Function to Access

  • From: "Jim Pettit" <j_e_pettit@xxxxxxxxxxx>
  • To: <mso@xxxxxxxxxxxxx>
  • Date: Fri, 4 Jun 2004 08:06:36 -0700

Glenda/All--

I brought your function into Access 2002, cleaned up the extraneous
characters, and tested it; it works fine. As it should; it's pure VBA,
and calls nothing that wouldn't be on any machine. Which is to say, it
should work for not just Access and Excel, but also Word, Project,
Visio, and any other application which uses VBA. Was your reason for
asking the question because it's *not* working in Access for you?

Anyway, just for kicks, here's the email validation function I use in
VBA; it makes use of the Regular Expression ActiveX object that's
present and available on any machine with IE 5.0 or newer:

Function IsEmailValid(sEmail) As Boolean
    Dim regEx As Object
    Dim retVal As Variant

    Set regEx = CreateObject("vbscript.regexp")
    regEx.Pattern =
"^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$"
    regEx.IgnoreCase = True
    retVal = regEx.Test(sEmail)
    If Not retVal Then
        IsEmailValid = False
    Else
        IsEmailValid = True
    End If
End Function

A little less verbose, wouldn't you say? Regular expressions are way too
cool...
 
--Jim

-----Original Message-----
From: mso-bounce@xxxxxxxxxxxxx [mailto:mso-bounce@xxxxxxxxxxxxx] On
Behalf Of Glenda Wells
Sent: Friday, June 04, 2004 6:43 AM
To: mso@xxxxxxxxxxxxx
Subject: [mso] Re: Excel Function to Access


here's the Excel code. it compiles and seems to work alright. please
keep in mind I modified this from a VB site where it was offered free
and just modified a tad for our use and my understanding  /g

' Function: IsEmailValid(strEmail)
' Action: checks email format
' Parameter: strEmail - the Email address
' Display: if proper format True, otherwise False
Function IsEmailValid(strEmail)
=20
    Dim strArray
    Dim strItem
    Dim i
    Dim c
    Dim blnIsItValid
=20
    ' if email address is properly formatted
    blnIsItValid =3D True
  =20
    ' separate into 2 values at @: addr@xxxxxxxxxx
    strArray =3D Split(strEmail, "@")
=20
    ' if more or less than two values: False
    If UBound(strArray) <> 1 Then
        blnIsItValid =3D False
        IsEmailValid =3D blnIsItValid
        Exit Function
    End If
=20
    ' neither value can be empty
    For Each strItem In strArray
      =20
        If Len(strItem) <=3D 0 Then
            blnIsItValid =3D False
            IsEmailValid =3D blnIsItValid
            Exit Function
        End If
      =20
        ' only allowed elements: alpha, numberic, underbar, hyphen, dot
      =20
        For i =3D 1 To Len(strItem)
               c =3D LCase(Mid(strItem, i, 1))
               ' if disallowed element found
               If InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <=3D 0 And =
Not
IsNumeric(c) Then
                   blnIsItValid =3D False
                   IsEmailValid =3D blnIsItValid
                   Exit Function
               End If
        Next
 =20
      ' beginning and ending element in either value cannot be dot
        If Left(strItem, 1) =3D "." Or Right(strItem, 1) =3D "." Then
           blnIsItValid =3D False
           IsEmailValid =3D blnIsItValid
           Exit Function
        End If
    Next
=20
    ' the 2nd value must contain dot
    If InStr(strArray(1), ".") <=3D 0 Then
        blnIsItValid =3D False
        IsEmailValid =3D blnIsItValid
        Exit Function
    End If
=20
    ' the extension of the 2nd value must be between 2 and 4 elements
    i =3D Len(strArray(1)) - InStrRev(strArray(1), ".")
    ' the length of the extension can be only 2, 3, or 4 characters
    If i <> 2 And i <> 3 And i <> 4 Then
        blnIsItValid =3D False
        IsEmailValid =3D blnIsItValid
        Exit Function
    End If

    ' no double dot
    If InStr(strEmail, "..") > 0 Then
        blnIsItValid =3D False
        IsEmailValid =3D blnIsItValid
        Exit Function
    End If
=20
    ' display True
    IsEmailValid =3D blnIsItValid
  =20
 End Function

-----Original Message-----
From: Jim Pettit [mailto:j_e_pettit@xxxxxxxxxxx]
Sent: Thursday, June 03, 2004 03:53 PM
To: mso@xxxxxxxxxxxxx
Subject: [mso] Re: Excel Function to Access

Everyone (& you too, Glenda)--

If A) the function is in VBA, and B) the function only makes use of
components you have installed (such as any DLL's or OCX's), it should
work. AS ray wrote, if you care to post the function here, I'm sure some
of us (that is, me) would be happy to test it out for you. ;-)

--Jim

-----Original Message-----
Subject: [mso] Excel Function to Access

I found some help online and surprised the heck out of myself by writing
a simple function in Excel that actually works to check simple rules for
email addresses.

Is there a way to make this thing work in Access?  I'm sure the two are
different...maybe?



  _____ =20

<< ella for Spam Control >> has removed 10901 Spam messages and set
aside 0 Newsletters for me You can use it too - and it's FREE!
www.ellaforspam.com=09
*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx
or MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, send an email to 
mso-request@xxxxxxxxxxxxx with the word "unsubscribe" (without the
quotes) in the subject line.

Or, visit the group's homepage and use the dropdown menu.  This will
also allow you to change your email settings to digest or vacation (no
mail). //www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group,
send a request to mso-moderators@xxxxxxxxxxxxx and you will be sent an
invitation with instructions.  Once you are a member of the files group,
you can go here to upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************
*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, send an email to 
mso-request@xxxxxxxxxxxxx with the word "unsubscribe" (without the quotes) in 
the subject line.

Or, visit the group's homepage and use the dropdown menu.  This will also allow 
you to change your email settings to digest or vacation (no mail).
//www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a 
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation with 
instructions.  Once you are a member of the files group, you can go here to 
upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************

Other related posts: