Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / April 2008

Tip: Looking for answers? Try searching our database.

assessing a string value to be a phone number

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Southern at Heart - 29 Apr 2008 12:59 GMT
I need to check to see if strPhone is a phone number with this format:
xxx-xxx-xxxx
It has to be this way or it won't work in the code further down the line
(which I can't change)

I can remove spaces from the beginning and end of it if they exist using
Left & Right fucntions.  But is there a way to verify that the 4th and 8th
char is the hypen, and that all the other chars are digits?
many thanks,
SouthernAtHeart
John Spencer - 29 Apr 2008 13:18 GMT
IF Trim(StrPhone) Like "###-###-####" Then

'====================================================
 John Spencer
 Access MVP 2002-2005, 2007-2008
 Center for Health Program Development and Management
 University of Maryland Baltimore County
'====================================================

> I need to check to see if strPhone is a phone number with this format:
> xxx-xxx-xxxx
[quoted text clipped - 6 lines]
> many thanks,
> SouthernAtHeart
Southern at Heart - 29 Apr 2008 13:47 GMT
WOW!  That's EASY!  THANKS!  This looks like a statement from a query, but
it'll work in VBA?
thanks so much!
SatH

> IF Trim(StrPhone) Like "###-###-####" Then
>
[quoted text clipped - 15 lines]
> > many thanks,
> > SouthernAtHeart
Linq Adams - 29 Apr 2008 14:49 GMT
Sure, you can use something like this, in VBA code

Private Sub strTelephone_BeforeUpdate(Cancel As Integer)
If Not (Trim(strTelephone) Like "###-###-####") Then
MsgBox "This is Not a Valid Phone Number!"
Cancel = True
End If
End Sub

to alert users that the number they entered is not a valid phone number.

Signature

There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Linq Adams - 29 Apr 2008 14:51 GMT
Sorry, for your object name strPhone, that should be:

Private Sub strPhone_BeforeUpdate(Cancel As Integer)
 If Not (Trim(strPhone) Like "###-###-####") Then
   MsgBox "This is Not a Valid Phone Number!"
   Cancel = True
 End If
End Sub

Signature

There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.