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