Solved

Test for no-value in control

Posted on 2001-06-08
5
192 Views
Last Modified: 2011-09-20
I have a report with 2 sub-reports. The report is a customer statement between 2 dates showing his/her orders and payments.

One sub-report shows all orders between the 2 dates, and the other sub-report shows all payments between the 2 dates. On each sub-report there is a non-visible control which is the sum of orders (or payments).

This non-visible control is used to supply the total orders and payments values to controls on the main report.
The controls on the main report have control source as:
=[sbrOrders].Report![txtSumOrders] and
=[sbrPayments].Report![txtSumPayments].

[sbrOrders] and [sbrPayments] are the names of the 2 sub-reports. [txtSumOrders] and [txtSumPayments] are the non-visible controls.

A problem occurs when there are no orders (or payments) between the 2 dates. There is no value in the total control on the main report, not even Null.

How do I test for this situation so that I can run alternative code?

Thanks.
0
Comment
Question by:Annu
5 Comments
 

Expert Comment

by:Al_a_Ddin
ID: 6170481
You may use this:
=iif(isnull([sbrOrders].Report![txtSumOrders])=true;0;=[sbrOrders].Report![txtSumOrders])
or like this
=iif(isnumeric([sbrOrders].Report![txtSumOrders])=true;0;=[sbrOrders].Report![txtSumOrders])
0
 

Expert Comment

by:Al_a_Ddin
ID: 6170483
Opps..
=iif(isnull([sbrOrders].Report![txtSumOrders])=true;0;[sbrOrders].Report![txtSumOrders])
and
=iif(isnumeric([sbrOrders].Report![txtSumOrders])=true;0;[sbrOrders].Report![txtSumOrders])
0
 
LVL 5

Expert Comment

by:dgorin
ID: 6171783
Or use something like

  If nz(sbrOrders.Value) > 0 Then
    Process
  Else
    Nothing there
  End if
0
 
LVL 6

Expert Comment

by:xSinbad
ID: 6172941
Have you tried the 'On No Data' evnt in the Report?
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 100 total points
ID: 6173260
The problem is that a subform or subreport with no records returns an error, not a null.  So you can either use IsError with an IIf check to return a zero:


=IIf(IsError([sbrOrders].Report![txtSumOrders]),0,[sbrOrders].Report![txtSumOrders])


 or you can use the function below like so:

=AvoidError([sbrOrders].Report![txtSumOrders])

Jim.

Function AvoidError(n As Variant)
         
    On Error GoTo Trap
    AvoidError = n
    Exit Function

Trap:
    AvoidError = 0
    Resume Next

End Function
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now