Dumb question #2... Run-time error 2427

L

Louie Warren

I have a report based on a query. I have some conditional
processing that changes the color of the text based on the
value of a field. When there is at least one row
retrieved, it works fine. However, when there are no rows
retrieved, instead of just printing the header with no
rows, I get the "Run-Time error 2427 You entered an
expression that has no value." message. I've tried
entering the If the field is not null perform the
processing, but with no luck.

Code:

If ReportField = "This" or ReportField = "That" Then
Label3.Forecolor = QBColor(5)
Else
Label3.Forecolor = QBColor(0)
End If

I want to code "If no results returned, then print header,
else do the above code."

Any ideas? Thanx.
 
M

MikeC

Louie,

That's not such a dumb question. With any luck, this
won't turn out to be a dumb answer.

See if this fixes it:

If Not IsNull(ReportField) And (ReportField = "This" Or
ReportField = "That") Then
Label3.Forecolor = QBColor(5)
Else
Label3.Forecolor = QBColor(0)
End If

Also, you can use the report's "On No Data" event to
display an informational message that says something
like, "No data exists for the parameters used by this
report." ...or whatever you like.
 
M

MikeC

On second thought...

The IF statement should be nested as:

If Not IsNull(ReportField) Then
If ReportField = "This" Or ReportField = "That" Then
Label3.Forecolor = QBColor(5)
End If
Else
Label3.Forecolor = QBColor(0)
End If
 
L

Louie Warren

I have done both, the nested Null check and the NoData
Event Check, separately and combined and still get this
message on the same line every time.
 
M

MikeC

Louie,

Try replacing the first IF statement with the one below:

If ReportField <> vbNullString Then


If this tweak doesn't resolve the problem, then there is
more going on here than I can diagnose.
 
T

Tim Ferguson

I have a report based on a query. I have some conditional
processing that changes the color of the text based on the
value of a field. When there is at least one row
retrieved, it works fine. However, when there are no rows
retrieved, instead of just printing the header with no
rows, I get the "Run-Time error 2427 You entered an
expression that has no value." message.

What event is this code running in?

Tim F
 
D

Dirk Goldgar

Louie Warren said:
I have a report based on a query. I have some conditional
processing that changes the color of the text based on the
value of a field. When there is at least one row
retrieved, it works fine. However, when there are no rows
retrieved, instead of just printing the header with no
rows, I get the "Run-Time error 2427 You entered an
expression that has no value." message. I've tried
entering the If the field is not null perform the
processing, but with no luck.

Code:

If ReportField = "This" or ReportField = "That" Then
Label3.Forecolor = QBColor(5)
Else
Label3.Forecolor = QBColor(0)
End If

I want to code "If no results returned, then print header,
else do the above code."

Any ideas? Thanx.

If the report's recordsource returns no data, the ReportField control
(which I take to be a bound control) will have no value, not even Null,
because the field to which it is bound does not exist. But if you have
this code in the Detail section's Format event, which would seem
reasonable, then you wouldn't get the error, because the that event
would not fire. If this is in a group header section's Format event, I
still don't think it would fire. So I'm guessing you have it in the
Report Header section's Format event. That event will fire, even if
there's no data, but none of the data-bound controls will have a value.

I believe you could use the report's HasData property to execute your
code only if there are actually records returned by the report's
RecordSource:

If Me.HasData Then
If ReportField = "This" or ReportField = "That" Then
Label3.Forecolor = QBColor(5)
Else
Label3.Forecolor = QBColor(0)
End If
End If
 

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