Results 1 to 8 of 8
  1. #1
    anthgav is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    86

    Make fields that are blank display 0

    I have a query and one of the fields has blank values if there is nothing to add up, is there a way I can make the blank values display 0 instead? The field in question is "qryUsedProductSpacePerBay.used_space_mm"



    Here is the SQL...

    Code:
    SELECT tblWarehouse.warehouse,
    tblArea.area,
    tblBay.bay,
    tblBay.bay_width_mm,
    tblBay.bay_depth_mm,
    tblBay.bay_height_mm,
    qryUsedProductSpacePerBay.used_space_mm,
    [bay_width_mm]-[used_space_mm] AS free_space_mm,
    tblBin.bin,
    tblBin.bin_width_mm,
    tblBinType.priority,
    tblAllocatedBin.allocated_bin_id,
    tblBinType.bin_type,
    qryAllocatedProductAndBin.product,
    tblProduct.width_mm,
    tblProduct.depth_mm,
    tblProduct.height_mm,
    tblProduct.row, tblProduct.deep,
    tblProduct.high, tblProduct.loose,
    tblProduct.width_required,
    tblProductData.long_description,
    tblProduct.additional_info,
    tblProductData.catalogue_number,
    tblProductData.bin_number,
    tblProductData.min_bin_qty,
    tblProductData.max_bin_qty,
    tblProductData.pallet_break,
    tblProductData.physical_qty,
    tblProductData.allocated_qty,
    tblProductData.back_order_qty,
    tblProductData.forward_order_qty,
    tblProductData.on_order_qty,
    tblProductData.quantity_in_bulk,
    tblProductData.package,
    tblProductData.demand_month_1, 
    tblProductData.demand_month_2, 
    tblProductData.demand_month_3, 
    tblProductData.demand_month_4, 
    tblProductData.demand_month_5, 
    tblProductData.demand_month_6, 
    tblProductData.demand_month_7, 
    tblProductData.demand_month_8, 
    tblProductData.demand_month_9, 
    tblProductData.demand_month_10, 
    tblProductData.demand_month_11, 
    tblProductData.demand_month_12
    FROM (qryUsedProductSpacePerBin RIGHT JOIN ((qrySumOfBinSize RIGHT JOIN (qryAllocatedProductAndBin RIGHT JOIN (((((tblWarehouse LEFT JOIN tblArea ON tblWarehouse.[warehouse_id] = tblArea.[warehouse]) LEFT JOIN tblBay ON tblArea.[area_id] = tblBay.[area]) LEFT JOIN tblBin ON tblBay.[bay_id] = tblBin.[bay]) LEFT JOIN (tblBinType RIGHT JOIN tblAllocatedBin ON tblBinType.[bin_type_id] = tblAllocatedBin.[allocated_bin_type])
    ON tblBin.[bin_id] = tblAllocatedBin.[allocated_bin]) LEFT JOIN tblProduct ON tblAllocatedBin.allocated_bin_id = tblProduct.[allocated_bin_1]) ON qryAllocatedProductAndBin.allocated_product = tblAllocatedBin.allocated_bin_id) ON qrySumOfBinSize.bay = tblBay.bay) LEFT JOIN tblProductData ON tblProduct.product = tblProductData.product) ON qryUsedProductSpacePerBin.bay = tblBay.bay) LEFT JOIN qryUsedProductSpacePerBay ON tblBay.bay = qryUsedProductSpacePerBay.bay
    WHERE (((tblBinType.bin_type) Is Not Null))
    ORDER BY tblWarehouse.warehouse, tblArea.area, tblBay.bay, tblBin.bin, tblBinType.priority;

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    convert nulls to zero: NZ([field],0)

  3. #3
    anthgav is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    86
    Thanks that works in Access but I use Excel to draw the data into a pivot table and it still shows as blank in the pivot table, any ideas why it doesn't translate to Excel via the query?

  4. #4
    anthgav is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    86
    I actually had a bit of a blonde moment and realised my pivot table was using a different front end file to the one I edited the query in which is why it was still showing blank.
    I have a new problem, Excel doesn't like NZ([field],0) being in the query and fails to refresh when it's included, is there an alternative way of achieving making blanks show as 0 that might work when being pulled from Excel?

  5. #5
    anthgav is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    86
    This seems to be compatible with Excel "IIF(ISNULL(qryUsedProductSpacePerBay.used_space_m m), 0, qryUsedProductSpacePerBay.used_space_mm)"

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You didn't specify the name of the query you posted in Post#1, so lets call it "Query1". (imaginative, No?)
    "Query1" has the "NZ([field],0)" in it.

    Create another query with "Query1" as the source. Add all of the fields to the grid. Name this query "qryExportForExcel".
    Open query "qryExportForExcel". Are the zeros there now?

  7. #7
    anthgav is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    86
    Quote Originally Posted by ssanfu View Post
    You didn't specify the name of the query you posted in Post#1, so lets call it "Query1". (imaginative, No?)
    "Query1" has the "NZ([field],0)" in it.

    Create another query with "Query1" as the source. Add all of the fields to the grid. Name this query "qryExportForExcel".
    Open query "qryExportForExcel". Are the zeros there now?
    When "used_space_mm: Nz([qryUsedProductSpacePerBay.used_space_mm],0) AS used_space_mm" is in the query Excel doesn't even detect the query so i can't select it, even after doing what you suggested by creating "qryExportForExcel".
    If I use "IIF(ISNULL(qryUsedProductSpacePerBay.used_spa ce_m m), 0, qryUsedProductSpacePerBay.used_space_mm) AS used_space_mm" in the query then Excel detects it and pulls through ok.
    This field "
    [bay_width_mm]-[used_space_mm] AS free_space_mm" uses the other field for a calculation but if "used_space_mm" is 0 then "free_space_mm" does not pull through to Excel in the report even though the figure shows up in Access.

    Not sure what I can do to make it pull through to Excel. Are there any other ways of achieving this?

  8. #8
    anthgav is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    86
    I managed to figure out a solution to make it compatible with the Excel report. The calculation in the "free_space_mm" field also needs to convert Null values to zeros despite the fact the lookup field already does it before hand.
    So i did "[bay_width_mm]-IIf(IsNull([used_space_mm]),0,[used_space_mm]) AS free_space_mm" Now this field displays correctly in Excel.

    Thanks guys you pointed me in the correct direction.

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

Similar Threads

  1. Replies: 3
    Last Post: 04-24-2016, 07:24 AM
  2. How to make blank fields NA
    By jenncivello in forum Queries
    Replies: 7
    Last Post: 09-11-2014, 10:27 AM
  3. Replies: 3
    Last Post: 01-08-2013, 02:41 PM
  4. Replies: 5
    Last Post: 06-11-2012, 08:47 AM
  5. make query fields not display if null data
    By rivereridanus in forum Queries
    Replies: 1
    Last Post: 07-05-2011, 08:19 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