IIf Help!!! again

  • Thread starter Thread starter Fia
  • Start date Start date
F

Fia

Hi
Thank's for the help I got, but I have another problem.
When Ord is a string I get Error 13, Type mismatch. I thougt the code below
would give me the result Ord, because it isn't True or False, not an error.
How can I escape that?

IIf(Ord=True,-1,IIf(Ord=False,0,Ord))

Thank's
Fia
 
Try using Cbool(ord) maybe this resolve it.

Basically this functions casts your value to an boolean value

- RAoul
 
Why is Ord a string? What are some of the possible values that may be placed
in Ord? As JaRa mentioned, you may be able to use CBool() to get around the
type mismatch error, but whether this will do what you want or not will
depend on what the possible values for Ord are and what exactly you are
trying to accomplish.

Judging from your expression, I'm guessing that if the text in Ord is "True"
or "False" that you want a Boolean value of True or False returned,
otherwise you want the text in Ord returned. While this can be done,
depending on where you put that result, you may still wind up with a type
mismatch, not from the expression itself, but from the assignment of where
you're sending the result to. If this is just the Control Source of a
calculated textbox, then you should be ok.

IIf(Ord = "True", True, IIf(Ord = "False", False, Ord))
or
IIf(Ord = "True", -1, IIf(Ord = "False", 0, Ord))

The two expressions above are equivalent. There is a difference between the
word True and the value True, which is why the quotes are positioned as they
are in the first expression.
 
Back
Top