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

Need help with this formula

Status
Not open for further replies.

spining123

Technical User
Jun 5, 2003
33
US
I created a formula to check for null fields. I have two number fields that I'm trying to add a slash "/" between the two fields. The problem is that all the fields are to be concatenated as one field; else it would be easier to use the Format Field for each field. But this is a run on report. I also need to format the data in both fields. The number fields are defined in my Microsoft Access table as
data type = number
field size = long integer
format = general number
decimal places = 0.

List is the code in my formula:
stringvar Fld4 := "";
numbervar Fld5 := 0;
numbervar Fld6 := 0;
OutContainerandItem := 0;
stringvar theslash := "/";

If isnull ({tblOne.FormofMaterial})
then Fld4 := ""
else Fld4 := ({tblOne.FormofMaterial}));

If isnull ({tblOne.Container})
then Fld5 := 0
else Fld5 := ({tblOne.Container});

If isnull({tblOne.ItemCount})
then Fld6 := 0
else Fld6 := ({tblOne.ItemCount});

If isnull ({tblOne.SpanYearBg})
then Fld7 := ""
else Fld7 := ({tblOne.SpanYearBg}));

At this point is where I have the problem trying to insert a slash "/" between the two number fields (if both fields are not equal to 0) and change the display of the data. The data in the number fields look like 34.00 5.00
I would like for the display to look
like 34 5
I get a string error with the trim command and concatenating the slash. I tried using totext(OutContainerAndItem) also.


If Fld5 <> 0 And Fld6 <> 0 Then
OutContainerAndItem = ((rtrim(Fld5),3) & &quot;/&quot; & (rtrim(Fld6),3))
Else
If Fld5 <> 0 And Fld6 = 0 Then
OutContainerAndItem = (rtrim(Fld5),3)
Else
If Fld5 = 0 And Fld6 <> 0 Then
OutContainerAndItem = (rtrim(Fld6),3) ;

Yes I'm lost....Any help is truly appreciated
 
If you use the ToText function, you can specify the format of the numbers. The second argument of ToText is the number of decimal places. For example, if Fld5 is 24, and Fld6 is 15, the formula:
Code:
 ToText(Fld5,0) + '/' + ToText(Fld6,0)
would return '24/15'.

Additionally, if your numbers are in the 1000's, to get rid of the thousands separator, supply the optional third argument to ToText (which is the thousands separator) like
Code:
ToText(fld5,0,'')

-dave
 
Thank you very much Dave for your quick response. I made the changes to my code and (of course) it works.


If Fld5 <> 0 And Fld6 <> 0 Then
OutContainerAndItem := ToText(Fld5,0) & '/' & ToText(Fld6,0)
Else
If Fld5 <> 0 And Fld6 = 0 Then
OutContainerAndItem := ToText(Fld5,0) & &quot; &quot;
Else
If Fld5 = 0 And Fld6 <> 0 Then
OutContainerAndItem := ToText(Fld6,0) & &quot; &quot;;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top