IT & Public health mangment expert

how to make Input mask for  email field in table field in Access 2013
Dr.Abdulwahab Al-anesiProjects Information Technology ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeCommented:
I don't usually use input masks.  Instead, in the BeforeUpdate event of the control, I would check to see whether the value in the Text property of the control meets general email formatting requirements.  It would look something like:

Private Sub txt_Email_BeforeUpdate(Cancel as integer)

    If me.txt_Email & "" = "" Then
        Cancel = False  'field left blank
    Elseif me.txt_Email Like "*@*.???" Then
        Cancel = False 'field meets standard email formatting
    Else
         Cancel = True
         Msgbox "Invalid email format"
    End If

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dr.Abdulwahab Al-anesiProjects Information Technology ManagerAuthor Commented:
I think I need more help>

I tried this but it did not work in my form:

Private Sub Pemail_BeforeUpdate(Cancel As Integer)
If Me.txt_Email & "" = "" Then
        Cancel = False  'field left blank
    ElseIf Me.txt_Email Like "*@*.???" Then
        Cancel = False 'field meets standard email formatting
    Else
         Cancel = True
         MsgBox "Invalid email format"
    End If
End Sub
0
Dale FyeCommented:
What "did not work"?  Did it give you an error?  Did you enter an invalid email and it didn't return a message?

Open the form in design view.  Click on your Pemail textbox, then open the properties window to the Events tab.  Does it have [Event Procedure] listed to the right of the BeforeUpdate event for that control?  If not, click on the dropdown and select that option.  Then click on the elipse (...) button to the right of that to make sure the code is in the right place.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
You will not be able to use an input mask in this case because of the variable number of characters.

Dale ...
"If me.txt_Email & "" = "" Then
        Cancel = False  'field left blank"


If the field is blank (Null) ... the BU even will not trigger.

mx
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Private Sub txt_Email_BeforeUpdate(Cancel as integer)

   'Most basic test .... could be amped up more ...
   If Len (me.txt_Email) >=6 AND  InStr(1,me.txt_Email, "@") >0 AND InStr(1,me.txt_Email, ".") >0  Then Exit Sub
   ' probably valid

   Cancel = True
   Msgbox "Invalid email format"


End Sub
0
Dale FyeCommented:
Joe,

"BU will not even trigger"

It will if it has been changed from something that is not NULL or blank.

awahab595,

Actually, I believe you could accomplish the changes Joe recommended by changing my original post.  Change:

ElseIf Me.txt_Email Like "*@*.???" Then

to

ElseIf Me.txt_Email Like "?*@?*.???" Then

This would require that the username and domain portions of the address be at least 1 character in length.
0
Dr.Abdulwahab Al-anesiProjects Information Technology ManagerAuthor Commented:
What worked with me is putting the following in the validation rule

Is Null Or ((Like "*?@?*.?*") And (Not Like "*[ ,;]*"))
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"What worked with me is putting the following in the validation rule "
Then you should accept your  own solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.