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!

IIF Abbreviation possible? 1

Status
Not open for further replies.

georgesOne

Technical User
Jul 2, 2004
176
JP
Hi,

I will be writing lots of queries which typically will include expressions like

....& IIF(Len(A.MonoName2)<>0, "/" & A.MonoName2 & "(" & Format(Weight2,"#0.00") & "g)","") &....

i.e. if A.MonoName2 is null then a nullstring should appear, otherwise the expression '/XXXX(55.55g)'.

Is there any effective way to make this shorter?

Thanks, georges
 
Take a look at the Nz() and IsNull() functions. One of them might help. Also, if your IIF statements are the same except for the field or control name, you could write a function to perform the IIF and only have to call the function with the field passed as an arguement in your queries.

Public Function FormatMonoName(x)
If IsNUll(x) then
FormatMonoName = ""
Else
' or whatever your format statement might be
FormatMonoName = blah, blah, blah - Format(x,"#0.00")
End If
End Function

Then call it in your queries

FormatMonoName(A.MonoName2)
 
if A.MonoName2 is null then a nullstring should appear
Take a look at the difference between the + and the & concatenation operators.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks to both of you.
I think writing functions for the specific purpose is a good idea. The in-built functions may not work, because I usually add something to the expression, so the final expression will not be Null.
Star for MoLaker.

Regards, Georges
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top