IF statements

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I read in Access 2000 that you can write IIf statements.
But what if I would just like to specify an If...Then
statement as criteria. For example I have to compare a
date entered in text format, to a date entered in date
format. The problem is that the dates not consistent,
meaning some months are single digits some are double, so
I cannot use the Left([fieldname],#) function. B/c it
would not be consistent. Therefore I was trying to write
an If statement to count the length, and depending on the
result could abstract the necessary characters and then
accordingly compare the data.
 
An IIF is an If...Then (well it's actually an
If...Then...Else, but can be used just as an If...Then).

IIf(Len([fieldname])=7,"0","")&[fieldname]

This would add a leading 0 to the existing field name if
the length is 7.

Here's another method:

Right("00000000"&[fieldname],8)

This adds leading zeros to the value.

Hope this helps.
 
Can I use the IIf statement to assign a new variable. As
in could i say IIf(Len([fieldname])=7,Left([fieldname],1))
to assign the variable to only the first character of the
string?? And then could I use the result and compare it to
something else??

-----Original Message-----
An IIF is an If...Then (well it's actually an
If...Then...Else, but can be used just as an If...Then).

IIf(Len([fieldname])=7,"0","")&[fieldname]

This would add a leading 0 to the existing field name if
the length is 7.

Here's another method:

Right("00000000"&[fieldname],8)

This adds leading zeros to the value.

Hope this helps.


-----Original Message-----
I read in Access 2000 that you can write IIf statements.
But what if I would just like to specify an If...Then
statement as criteria. For example I have to compare a
date entered in text format, to a date entered in date
format. The problem is that the dates not consistent,
meaning some months are single digits some are double, so
I cannot use the Left([fieldname],#) function. B/c it
would not be consistent. Therefore I was trying to write
an If statement to count the length, and depending on the
result could abstract the necessary characters and then
accordingly compare the data.
.
.
 
Back
Top