[mso] Re: Excel Function to Access

  • From: "Jim Pettit" <j_e_pettit@xxxxxxxxxxx>
  • To: <mso@xxxxxxxxxxxxx>
  • Date: Fri, 4 Jun 2004 09:03:55 -0700

Glenda/All--

Sorry; I didn't mean to cause any consternation with that whole Regular
Expressions thing; I was just showing a different way of approaching the
same problem: validating an email address. Either function (yours or
mine) can be called from within any form or standard module in Access.
Lemme 'splain:

1) In your Access MDB, click on the 'Modules' tab, and then select
'New'.

2) Enter (or paste) your function (or, you know, mine).

3) Save the module using whatever name you want ('modValidate' would be
fine, but that's my preference).

4) Create a form with a textbox bound to the underlying email address
field.

5) In that textbox's 'AfterUpdate' event, place your code. Here's an
oversimplified version that assumes your textbox is named 'txtEmail':

Private Sub txtEmail_AfterUpdate()
    If RegExpTest(Me!txtEmail) Then
        MsgBox "You entered a properly formatted email address.",
vbOKOnly + vbInformation, "Success!"
    Else
        MsgBox "You entered an improperly formatted email address; try
again.", vbOKOnly + vbExclamation, "Failure!"
        Me!txtEmail = ""
        Me!txtEmail.SetFocus
    End If
End Sub

6) Toast yourself with a glass of champagne.

Because we placed the function in a module, it's available anyplace in
the application. Simple, no?

You know, Shakespeare we're not, we're all, simply, monkeys. It's just
that some of us have been hanging out in this dank corner of the zoo
longer than have others, so we've had more time to peck away at our
thousand keyboards. ;-)

--Jim

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


Thank you Jim.

The reason I asked is because I know zip...zero...nada...nothing about
VB or VBA.  I've picked up a few things from this list and searching the
web but that just means I'm a...monkey [see, monkey do]...no intelligent
lifeform here.=20

Your solution is definitely cleaner and more elegant. Just to point out
my lack of knowledge in this venue, I have nary a clue as to what this
means:  "Regular Expression ActiveX object" and no idea how to apply
your function.  Where for example, in Access would I place it and make
it run?

I only managed to get "mine" to work in Excel because I figured out how
add it in the VB editor...that is, I kept poking around until something
happened (...given infinite time, a thousand monkeys with typewriters
would eventually write the complete works of Shakespeare...)

/g

-----Original Message-----
From: Jim Pettit [mailto:j_e_pettit@xxxxxxxxxxx]
Sent: Friday, June 04, 2004 11:07 AM
To: mso@xxxxxxxxxxxxx
Subject: [mso] Re: Excel Function to Access

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

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

--Jim




  _____ =20

<< ella for Spam Control >> has removed 10902 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: