IIF(ISNULL(...),NULL,...) fires: invalid use of null (?????)

R

rocco

Does anyone know whay this:

Select Case RST.Fields(i).Name
Case "data", "startdate", "endDate"
RST.Fields(i) =
IIf(IsNull(Forms(ff.Name).Section(acDetail).Controls(RST.Fields(i).Name).Value),
Null,
ConvertiDataISO(Forms(ff.Name).Section(acDetail).Controls(RST.Fields(i).Name).Value))
Case Else
.....
End Select

will always fire an error: invalide use of null on the field enddate, which
can really happen to be NULL

while this:

Select Case RST.Fields(i).Name
Case "data", "startdate", "endDate"

If
IsNull(Forms(ff.Name).Section(acDetail).Controls(RST.Fields(i).Name).Value)
Then
RST.Fields(i).Value = Null
Else
RST.Fields(i).Value =
ConvertiDataISO(Forms(ff.Name).Section(acDetail).Controls(RST.Fields(i).Name).Value)
End If

Case Else
.....
End Select

works just fine? Didn't both do the same thing?

The table field "enddate" can accept Null values.
I tried importing everything in a new database thinking of some kind of
corruption. But didn't fix it...

There should be something with the IIF function, I guess.

Thanks,
Rocco
 
H

hmadyson

I believe that IIF only works in queries, and it looks like you are using it
in VBA, so you need the second syntax in order to work in VBA.

Please let me know if I can provide more assistance.
 
T

Tim Ferguson

There should be something with the IIF function, I guess.

RTFM

IIf() is a function, therefore all its parameters are evaluated before the
results are passed to it. If one of those evaluations fails, then so does
the whole call.

Hope that helps


Tim F
 

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