Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / June 2007

Tip: Looking for answers? Try searching our database.

Add to my string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob V - 19 Jun 2007 01:16 GMT
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)," "))
Graham Mandeno - 19 Jun 2007 03:23 GMT
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.
Signature

Good Luck  :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

> I want to add these two strings to this string so as they are on the last
> 2 lines, Thanks for any help.....Bob
[quoted text clipped - 10 lines]
>
> & IIf(IsNull(tblOwnerInfo.GSTRacingYesNo,Chr(13) & Chr(10)," "))
Bob V - 19 Jun 2007 23:08 GMT
Thanks graham, wish training race horses was that easy....Regards Bob Vance

> Hi Bob
>
[quoted text clipped - 40 lines]
>>
>> & IIf(IsNull(tblOwnerInfo.GSTRacingYesNo,Chr(13) & Chr(10)," "))
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.