Re: If/Then in Access 2007
- From: "vanderghast" <vanderghast@com>
- Date: Tue, 27 Oct 2009 15:14:49 -0400
Simple twist I learnt from C/C++, starting with the constant you want to check rather than the variable you want to check, but any 'side' is ok. In C/C++, = only means assignment, it is == which is used for comparison, so:
0 = variable
is catch by the compiler to be an error (you cannot assign a constant) while what you want is probably a test: 0 == variable. Doing
variable = 0
won't catch the error, and will place a zero in your variable. Bug hard to catch. So the 'twist' is to educate your mind to start with the constant. That possible bug does not exist in C#, since
if( variable = 0 )
is an error (can't cast an integer, 0, to a Boolean). The bug does not exists in VBA since = means and an assignment, and a comparison test and the compiler catches which one is which from the context.
Vanderghast, Access MVP
"Dale Fye" <dale.fye@xxxxxxxxxx> wrote in message news:904350AD-2CD4-447E-A7D4-A0EF0994B960@xxxxxxxxxxxxxxxx
Michel
Any particular reason why you used the syntax:
0 <> len(office111 & "")
instead of:
len(office111 & "") <> 0
I've always put the expression to be evaluated on the left of the comparison
operator(s) , and was just wondering whether there is a reason for doing it
in reverse?
----
Dale
"vanderghast" wrote:
IIf([Office111]<>"" , "+" , "" )
& [Office1] & " " & [Office11] & " " & [Office111]
Note that when you say "empty" , I assume you mean just that, a string with
no character in it. IT IS NOT the same as being NULL (unkown data, not
available, not appropriate, ... ). If you have to include also this case,
try:
iif( 0 <> len(office111 & "") , "+", "" )
& ...
Vanderghast, Access MVP
"Thomas Hirschmann" wrote in message
news:20091027104457tmh@xxxxxxxxxxxxxxxxxxxx
>I can't figure out the "IF" code for the follwong list I'm trying to
>compile:
>
> The "Table" field I'm trying to query is "Office111". If that field is > not
> empty, a "+" should be added to the output document. If the "Office111"
> field is empty, then nothing should be added. I tried this but I'm > getting
> "The expression you entered contains invalid syntax".
>
> CHNummer: IIf([Office111]<>"" "+") & "" & [Office1] & " " & [Office11] > & "
> " & [Office111]
>
> Any help would be most appreciate. Thanks.
> Tom
>
>
> EggHeadCafe - Software Developer Portal of Choice
> Full-Text Search with SQL Server 2000
> http://www.eggheadcafe.com/tutorials/aspnet/7e941095-d74f-449d-8f52-e6f5b6320397/fulltext-search-with-sql.aspx
.
.
- Follow-Ups:
- Re: If/Then in Access 2007
- From: Dale Fye
- Re: If/Then in Access 2007
- References:
- If/Then in Access 2007
- From: Thomas Hirschmann
- Re: If/Then in Access 2007
- From: vanderghast
- Re: If/Then in Access 2007
- From: Dale Fye
- If/Then in Access 2007
- Prev by Date: Re: outer join not working
- Next by Date: Re: If Statement or ?
- Previous by thread: Re: If/Then in Access 2007
- Next by thread: Re: If/Then in Access 2007
- Index(es):
Relevant Pages
|