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

Create Custom Function for Numeric or Alpha Field

Status
Not open for further replies.

BobDennison

Programmer
Jul 28, 2010
24
US
I find that I am concatenating 3 fields together alot so I thought I would create a custom function. The problem is that sometimes the 2nd and/or 3rd elements can be either numeric or alpha data (as defined in their respective databases). I would like to be able to pass the 3 variables to a function, test them to see if they are numeric and convert them to text if they are. Then the function would return a string containing the concatenated value.

Here is a code snippet of what I am trying to do. Can this be done?

Function (StringVar anyfield1, StringVar anyfield2, StringVar anyfield3)

If isNumeric(anyfield2) then
anyfield1 & "-" & toText(anyfield2,'#',0) & "-" & anyfield3
Else
anyfield1 & "-" & anyfield2 & "-" & anyfield3;

(this code is only checking to see if the second value is a number. I haven't even begun to address the 3rd value since I can't get this to work yet).

The problem is that this does not work if the anyfield2 or anyfield3 data types in the table are defined as numeric (which they are in some of our databases, even though they will always be numbers). I was hoping not to have to create multiple custom functions to handle all possible cases of combinations of alpha and numeric data.

Do I have to have the report writers that want to use this function convert their "anyfield2" and "anyfield3" values to text before they can pass it to the function? Any help would be appreciated.


 
The easiest way to do this will be to have the report developers always convert the values to string.

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
I suspected that would be the way to do it, but I was hoping for a different way to do it. Thank you for your reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top