Add to my string

B

Bob V

I want to add these two strings to this string so as they are on the last 2
lines, Thanks for any help.....Bob

NameAddress: IIf(IsNull(tblOwnerInfo.OwnerTitle),'',tblOwnerInfo.OwnerTitle
& ' ') &
IIf(IsNull(tblOwnerInfo.OwnerFirstName),'',tblOwnerInfo.OwnerFirstName & '
') & IIf(IsNull(tblOwnerInfo.OwnerLastName),'',tblOwnerInfo.OwnerLastName) &
Chr(13) & Chr(10) &
IIf(IsNull(tblOwnerInfo.OwnerAddress),'',Replace(tblOwnerInfo.OwnerAddress,Chr(13)
& Chr(10)," "))

& IIf(IsNull(tblOwnerInfo.GSTRacingNumber,Chr(13) & Chr(10)," "))

& IIf(IsNull(tblOwnerInfo.GSTRacingYesNo,Chr(13) & Chr(10)," "))
 
G

Graham Mandeno

Hi Bob

There's a very useful trick you can use here. In many ways the + and &
operators behave the same way with strings, but not where one or the
operands in Null.

These give the same result:
"String1" & "String2" = "String1String2"
and
"String1" + "String2" = "String1String2"

But:
"String1" & Null = "String1"
and
"String1" + Null = Null

So, you can wrap the component fields that might be Null, along with the
bits that go with them, in parentheses using +, and join them all together
using &. This way, nearly all your "IIf"s can disappear:

NameAddress: (OwnerTitle + ' ') & (OwnerFirstName + ' ') & OwnerLastName
& IIf(IsNull(OwnerAddress),'',
Chr(13) & Chr(10) & Replace(OwnerAddress,Chr(13) & Chr(10)," "))
& (Chr(13) + Chr(10) + GSTRacingNumber) & (Chr(13) + Chr(10) +
GSTRacingYesNo)

Note that the IIf for OwnerAddress is still required because Replace will
return an empty string, not a Null, if you pass it a Null.
 
B

Bob V

Thanks graham, wish training race horses was that easy....Regards Bob Vance

Graham Mandeno said:
Hi Bob

There's a very useful trick you can use here. In many ways the + and &
operators behave the same way with strings, but not where one or the
operands in Null.

These give the same result:
"String1" & "String2" = "String1String2"
and
"String1" + "String2" = "String1String2"

But:
"String1" & Null = "String1"
and
"String1" + Null = Null

So, you can wrap the component fields that might be Null, along with the
bits that go with them, in parentheses using +, and join them all together
using &. This way, nearly all your "IIf"s can disappear:

NameAddress: (OwnerTitle + ' ') & (OwnerFirstName + ' ') & OwnerLastName
& IIf(IsNull(OwnerAddress),'',
Chr(13) & Chr(10) & Replace(OwnerAddress,Chr(13) & Chr(10)," "))
& (Chr(13) + Chr(10) + GSTRacingNumber) & (Chr(13) + Chr(10) +
GSTRacingYesNo)

Note that the IIf for OwnerAddress is still required because Replace will
return an empty string, not a Null, if you pass it a Null.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Bob V said:
I want to add these two strings to this string so as they are on the last
2 lines, Thanks for any help.....Bob

NameAddress:
IIf(IsNull(tblOwnerInfo.OwnerTitle),'',tblOwnerInfo.OwnerTitle & ' ') &
IIf(IsNull(tblOwnerInfo.OwnerFirstName),'',tblOwnerInfo.OwnerFirstName &
' ') &
IIf(IsNull(tblOwnerInfo.OwnerLastName),'',tblOwnerInfo.OwnerLastName) &
Chr(13) & Chr(10) &
IIf(IsNull(tblOwnerInfo.OwnerAddress),'',Replace(tblOwnerInfo.OwnerAddress,Chr(13)
& Chr(10)," "))

& IIf(IsNull(tblOwnerInfo.GSTRacingNumber,Chr(13) & Chr(10)," "))

& IIf(IsNull(tblOwnerInfo.GSTRacingYesNo,Chr(13) & Chr(10)," "))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top