Results 1 to 2 of 2
  1. #1
    Star Lounger
    Join Date
    Jan 2002
    Location
    Massachusetts, USA
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Validation and Link (2002(XP))

    I have an e-mail field and need to make a rule for the AAAAA@AAAAAA format. I also want the mail to be a hyperlink in forms and such so you can click on it and have it launch the mail program. is there a way to do that.

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Validation and Link (2002(XP))

    If you are looking for something like an input mask for an e-mail field, you won't find one. Input masks use fixed number of characters. You can use a validation procedure to ensure there is a "@" symbol in the address entered in e-mail field, but that's about it.

    For e-mail addresses I always use a text field (hyperlink fields cause nothing but trouble). Typically use command button to open new e-mail message based on text in e-mail field, using code like this:
    <pre>Private Sub EMAIL_btn_Click()
    With Me
    If Not IsNull(.txtEmail) Then
    .EMAIL_btn.Hyperlink.Address = "mailto:" & .txtEmail
    Else
    .EMAIL_btn.Hyperlink.Address = ""
    MsgBox "E-mail address not entered.", vbCritical, "NO E-MAIL"
    End If
    End With
    End Sub</pre>

    In this example "EMAIL_btn" is the command button that opens email, and txtEmail is textbox bound to email field. As for validation for e-mail address, here is example:
    <pre>Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim strMsg As String
    With Me
    If Not IsNull(.txtEmail) Then
    If (InStr(1, [Email], "@") <= 1 Or _
    InStr(1, [Email], "@") = Len([Email])) Or _
    (InStr(1, [Email], "@") <> InStrRev([Email], "@")) Then
    strMsg = "Please enter valid e-mail address."
    MsgBox strMsg, vbExclamation, "INVALID E-MAIL ADDRESS!"
    Cancel = True
    .txtEmail.SetFocus
    End If
    End If
    End With
    End Sub</pre>

    If using this, add this event procedure for command button to prevent opening email msg with bogus address:
    <pre>Private Sub EMAIL_btn_Enter()
    If Me.Dirty Then Me.Refresh
    End Sub</pre>

    Also if using a custom "SAVE" button add error handling to clear Err No 2501 in event you cancel update. The validation procedure above verifies that: (a) there is an "@" in email address (InStr > 0); ([img]/forums/images/smilies/cool.gif[/img] there is ONLY one "@" (compare InStr & InStrRev return values, should be equal); and the "@" is somewhere in middle of email address, not 1st or last character (InStr <>1 and <> Len of string). Of course this won't prevent a determined user from entering incorrect email address.

    HTH or gives you some ideas.

Posting Permissions

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