Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula question 1

Status
Not open for further replies.

savok

Technical User
Jan 11, 2001
303
AT
I have a Phone formula where I format the phone and put dashes in.

Left ({people.tel1}, 3) + "-" + Mid ({people.tel1}, 4,3) + "-" + Mid ({people.tel1}, 7,4)


Now lets say the phone is empty, then it shows 2 dashes.
I dont want it to show anything at all. What can I do?

I tried doing
If not isnull({people.tel1}) then
Left ({people.tel1}, 3) + "-" + Mid ({people.tel1},
4,3) + "-" + Mid ({people.tel1}, 7,4)

but it didnt work

any suggestions?
 
Give this a try.

If isnull({people.tel1}) Then " "
Else Picture({people.tel1},'xxx-xxx-xxxx')
 
... or, you can name your formula @FormatPhone: Left ({people.tel1}, 3) + "-" + Mid ({people.tel1}, 4,3) + "-" + Mid ({people.tel1}, 7,4)

then do the following:

If IsNull(@FormatPhone) = True Then
""

Else
@FormatPhone

=^..^=
 
thanks guys, but for some reason both of the ways didnt work :(

i did get it to work like this though

if (Length ({people.tel1})) = 0 then
""
else
{@FormatPhone}


thanks ;)
 
Length ({people.tel1}) = 0
and
isnull({people.tel1})

aren't the same thing in most databases.

The first is a string with no characters in it, the second is a field that's never had any data in it. The way to test for either possibility is:

If (Length ({people.tel1}) = 0) or (isnull({people.tel1})) then &quot;&quot; else <whatever you're doing>
 
You might want to address both possible conditions then to make is more bullet proof:

if(Length({people.tel1})) <> 0 or not isnull({people.tel1}) then
{@FormatPhone}
else
&quot;&quot;;


 
sorry...the previous formula should be:

if(Length({people.tel1})) <> 0 and not isnull({people.tel1}) then
{@FormatPhone}
else
&quot;&quot;;


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top