Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Mar 2003
    Location
    Ilkeston, Derbyshire
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    email address validation (access 2000)

    Does anyone know where I might find a VBA function that can do email address validation? Free would be good too <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    TIA
    Mark

  2. #2
    Star Lounger
    Join Date
    Mar 2003
    Location
    Ilkeston, Derbyshire
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: email address validation (access 2000)

    John

    I'm just after a check to make sure the addreess is syntactically correct. Your function looks like it will do the trick. May I use it? And if so, how would you like creditting?

    Mark

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: email address validation (access 2000)

    Do you just want to check that the address is constructed in a way that could be valid, or do you want to test that it really works?

    I use the following function to check that an address is reasonable.

    Public Function fnValidateEmail(myaddress As String) As Boolean
    'checks to see if any email address is reasonable
    Dim Position As Long
    Dim valid As Boolean
    Dim strMessage as string
    Position = InStr(1, myaddress, "@")
    valid = True
    If Position = 0 Then
    ' no @ symbol
    valid = False
    Else
    If (Len(Left$(myaddress, Position - 1)) = 0) Or (Len(Right$(myaddress, Len(myaddress) - Position)) = 0) Then
    ' then @ symbol is at one end of the address
    valid = False
    End If
    End If
    If InStr(1, Right$(myaddress, Len(myaddress) - Position), ".") = 0 Then
    ' no . in address after @
    valid = False
    ElseIf InStr(1, Right$(myaddress, Len(myaddress) - Position), ".") = Len(Right$(myaddress, Len(myaddress) - Position)) Then
    ' . is at the end
    valid = False
    End If
    If InStr(1, myaddress, " ") > 0 Then
    ' address contains a space
    valid = False
    End If
    If ( valid = false) Then
    strMessage = "This email address is not valid. Either correct it or delete it." & vbNewLine &
    strMessage = strMessage & " An email address must contain one @ with something to the left of it, no spaces, and at least one . with something after it."
    msgbox strMessage
    End If
    fnValidateEmail = valid
    End Function

    I call the function whenever I try to send a message, or update an email address.
    edited by John to improve layout
    Regards
    John



  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: email address validation (access 2000)

    Mark

    Feel free to use it however you like.

    Here are a couple of examples of how I use it.

    Private Sub Email_BeforeUpdate(Cancel As Integer)
    Dim validaddress As Boolean
    If Not IsNull(Me!Email) Then
    validaddress = fnValidateEmail(Me!Email)
    If Not validaddress Then
    'Message is supplied by the function
    Cancel = true
    End If
    End If
    End Sub

    Private Sub Email_DblClick(Cancel As Integer)
    On Error GoTo Error_Email_DblClick
    Dim strAddress As String
    If Not IsNull(Me!Email) Then
    If fnValidateEmail(Me!Email) = True Then
    strAddress = "mailto:" & Me!Email
    Application.FollowHyperlink strAddress, , True
    End If
    End If

    Exit_Email_DblClick:
    Exit Sub

    Error_Email_DblClick:
    MsgBox Err & ": " & Err.Description
    Resume Exit_Email_DblClick
    End Sub
    Regards
    John



  5. #5
    Star Lounger
    Join Date
    Mar 2003
    Location
    Ilkeston, Derbyshire
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: email address validation (access 2000)

    Nice one!

    Many thanks
    Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •