By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,567 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

VBA doesn't recognize @ sign

P: n/a
Hi Everybody

Is there any way to write a piece of code
something like this:

If Me.txtFrom = Like ""[@*]*""" then
do this
End if

If Me.txtFrom <> Like ""[@*]*""" then
do that
End if

The @ sign is a forbidden symbol

The idea is to trap where a user may not have entered a correct Email
address.

Thanks to all

Smiley Bob

Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Bob,

Try this instead:

If InStr([EmailAddress],"@") = 0 Then
MsgBox "Invalid Email Address"
End If

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Bob Dydd" <sm*******@hotmail.com> wrote in message
news:9f********************************@4ax.com...
Hi Everybody

Is there any way to write a piece of code
something like this:

If Me.txtFrom = Like ""[@*]*""" then
do this
End if

If Me.txtFrom <> Like ""[@*]*""" then
do that
End if

The @ sign is a forbidden symbol

The idea is to trap where a user may not have entered a correct Email
address.

Thanks to all

Smiley Bob

Nov 13 '05 #2

P: n/a
Hi

Thanks for that.

It traps that error elegantly

Bob

On Wed, 21 Jul 2004 13:56:19 GMT, "PC Datasheet" <no****@nospam.spam>
wrote:
Bob,

Try this instead:

If InStr([EmailAddress],"@") = 0 Then
MsgBox "Invalid Email Address"
End If


Nov 13 '05 #3

P: n/a
Bob Dydd <sm*******@hotmail.com> wrote in
news:9f********************************@4ax.com:
Hi Everybody

Is there any way to write a piece of code
something like this:

If Me.txtFrom = Like ""[@*]*""" then
do this
End if

If Me.txtFrom <> Like ""[@*]*""" then
do that
End if

The @ sign is a forbidden symbol

The idea is to trap where a user may not have entered a correct Email
address.

Thanks to all

Smiley Bob


Or, add a reference to Microsoft VB Script Regular Expressions 5.5 (if you
have Win2K or XP, not a problem, otherwise, you need to download the
Windows Scripting Host stuff from Microsoft).

Public Function Find(target As String, source As String) As String
Dim rexp As New RegExp
Dim rxMatches As MatchCollection
Dim rxMatch As Match

rexp.Pattern = target
Set rxMatches = rexp.Execute(source)
For Each rxMatch In rxMatches
Debug.Print rxMatch.Value
Next rxMatch

End Function
Nov 13 '05 #4

P: n/a
Bob Dydd <sm*******@hotmail.com> wrote in
news:9f********************************@4ax.com:
Hi Everybody

Is there any way to write a piece of code
something like this:

If Me.txtFrom = Like ""[@*]*""" then
do this
End if

If Me.txtFrom <> Like ""[@*]*""" then
do that
End if

The @ sign is a forbidden symbol

The idea is to trap where a user may not have entered a
correct Email address.

Thanks to all

Smiley Bob

If nobody has answered you yet, the right way to write the code you
want is If Me.txtFrom Like "*@*" then
and If Me.txtFrom NOT Like "*@*" then
--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.