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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Formula based on of characters in a field

Status
Not open for further replies.

meagain

MIS
Nov 27, 2001
112
CA
Hello Everyone,

Within an update query, I need to set up a formula that will analyze a field's data and a) leave it as is if there are 3 or less characters or b) append a "-" after the third character, when there are 4 characters present or c) append a "-" after the third character and a "0" at the end, when there are 5 characters. While I know how to word the conversion of the data, I'm unaware of a function which can determine the # of characters in a field. Is there such a function?

Here's an example of the data in the field and how it should look after conversion;

"G" needs to remain "G"
"A66" needs to remain "A66"
"D15A" needs to become "D15-A"
"B32A1" needs to become "B32-A10"

If you know of a function or if you think there is a better way to go about this without counting the characters, please let me know.

Thanks for any help you can provide.
 
Why not
Code:
UPDATE tblTest1 SET tblTest1.flda = Left([flda],3) & "-" & Mid([flda],4)
WHERE ((Len([flda])>"3"));

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
THis should get you started, which is obviously all you need..

Expr1: IIf(Len([strFieldName])<4,[strFieldName],IIf(Len([strFieldName])=4,Left([strFieldName],3) & "-" & Right([strFieldName],1),"etc!!"))

Lilliabeth
-Why use a big word when a diminutive one will do?-
 
Thank you both Greg and Lilliabeth, "LEN" was what I was looking for.

Lori
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top