Solved

Test for no-value in control

Posted on 2001-06-08
5
196 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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 the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

730 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