Results 1 to 6 of 6
  1. #1
    FJM is offline Competent Performer
    Windows 98/ME Access 2003
    Join Date
    Jun 2010
    Posts
    117

    Do not print report if total is zero

    I have a report based on an expression which shows me a financial value for individual items and then summarises the individual values to give a total for the report .
    To preview the report the user enters a start and finish date via a calendar.
    I want a message to appear and the report not to print if the total value of the items is ZERO - similar to the warning message you can receive from the ON NO DATA option


    Anyone have any ideas ?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    check the count 1st...

    Code:
    if Dcount("*","qsQrySum") = 0 then
       MsgBox  "No records produced.", vbInformation, "Print Canceled"
    else
       DoCmd.OpenReport "rTotals", acViewPreview
    endif

  3. #3
    FJM is offline Competent Performer
    Windows 98/ME Access 2003
    Join Date
    Jun 2010
    Posts
    117
    At the moment, the report is opened up by a command button which has an embedded macro linked to the "On click" action.
    Where would I enter your code

  4. #4
    FJM is offline Competent Performer
    Windows 98/ME Access 2003
    Join Date
    Jun 2010
    Posts
    117
    Can you also help with the code
    The report name is
    NCR Low Value COST

    wITHIN the report, the Total cost expression is
    =Sum(nz([Credit amount],0)+nz([NEWITEMCOSTTOCPE],0)+nz([CARRIAGEOUTWARD],0)+nz([COLLECTIONCOST],0)-nz([CREDITFROMCARRIER],0)-nz([COSTOFRETURNEDSTOCK],0))

    Can you now re-write your code.
    Also, would I cancel the embedded macro and simply replace it with your code ?
    Thank you

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Remove the macro..
    in the box where the macro goes, to the right is an elipsis box [...]
    click it to goto code
    paste inside the OnClick event.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Ranman's code will work if you have ONE field in your source query that has the value you want, which it doesn't. Your 'check' value is a sum of multiple rows in your query, probably by an order number or something so you would have to account for that in your domain function or it will give you unexpected results. Ranman's suggestion is also COUNTING rows, not SUMMING rows which will really give you the wrong results as I would imagine, again you have multiple rows per order.

    so you can do one of two things.
    1. Create a query that has the calculation you want and use ranman's suggestion but count the items in that summarized query
    or
    2. Create a domain function that addresses your calculation need for instance:

    dsum("nz([Credit amount],0)+nz([NEWITEMCOSTTOCPE],0)+nz([CARRIAGEOUTWARD],0)+nz([COLLECTIONCOST],0)-nz([CREDITFROMCARRIER],0)-nz([COSTOFRETURNEDSTOCK],0)", "SOURCEQUERY")

    if your source query has multiple rows but it's all related to the same item you're reporting on this would work.
    If the source query has multiple rows but they are NOT all related to the same item you're reporting on you'd have to add a 'where' clause to your domain function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 03-01-2014, 07:07 AM
  2. Replies: 3
    Last Post: 03-11-2013, 05:11 PM
  3. Replies: 1
    Last Post: 12-03-2012, 03:15 PM
  4. Replies: 0
    Last Post: 02-22-2011, 05:04 AM
  5. Replies: 1
    Last Post: 06-29-2010, 03:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums