Results 1 to 11 of 11

Thread: Why does this not work? **Resolved**

  1. #1

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Why does this not work? **Resolved**

    On the footer of a from set to "Continuous Forms" I have a text box with this code in it.

    =IIf(IsNull(Sum([FinalPrice])),0,Sum([FinalPrice]))

    FinalPrice is the name of a text box that contains another calculation. Why should this not work this time?

    Last time I did this the form was backed by a table and was filtered. this time it's backed by a query. surely that's not the reason!?

    the output is: #Error
    Last edited by Matt_T_hat; Jul 31st, 2003 at 06:04 AM.
    ?
    'What's this bit for anyway?
    For Jono

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    This is an Access report? Your syntax is correct, but the
    issue may be from the text box not yet being displayed so it is
    neither null or 0. So by the IIF statement it will go to the false
    scenerio. Then when it tries to display the contents there is
    nothing to display so the formula get the #ERROR. You can not do
    a SUM on all the instances of a text box. Can you use the field
    from the query instead?

    Can you post more information so we can be able to guide you in
    the right direction?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    Another possibility is this: If the [Final Price] does not contain a value in every record then the result will be #Error as Access cannot Sum a null. I would suggest that you add a further condition to your query controlsource for [Final Price]. Something along the lines of iif(isnull([Final Value],0,[Final Value]) so you don't have any empty fields being summed.

    Just a thought.

  4. #4

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    [Final value] is a calculated result and at present with some junk data in the DB no blank fields result.

    From expirence nothing to add up results in nul returned and no maths is done.


    Something along the lines of iif(isnull([Final Value],0,[Final Value]) so you don't have any empty fields being summed.
    is a stunning idea but doesn't help much at the mo.

    Still work is over for the day.
    ?
    'What's this bit for anyway?
    For Jono

  5. #5

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    IT's an access 2000 database

    The control source is now set to =sum([finalprice]) and still nothing.

    It errors whatever I do.

    For a time a second textbox set as defult = sum([finalprice]) gave the first row as an answer but that sits there blank.

    I can find no deviation from when I've done it before.

    FinalPrice is achieved via =([Unit Price]*[AmmountReq]) as the control

    and the whole is backed by a query that has SQL:

    Code:
    SELECT Job.[Job ID], Example.Discriptor, Example.Size, Feature.Name, Feature.Measure, Material_Required.Qantity, _
    [GET Cheapest Supplier].Qty, [GET Cheapest Supplier].Unit.Name, [GET Cheapest Supplier].[Unit Price], [GET Cheapest Supplier].[Unit ID], _
    [GET Cheapest Supplier].Supplier.Name
    FROM (Feature LEFT JOIN ([GET Cheapest Supplier] RIGHT JOIN Material_Required ON [GET Cheapest Supplier].[Unit ID] = _
    Material_Required.[Unit ID]) ON Feature.[Feature ID] = Material_Required.[Feature ID]) RIGHT JOIN (Job LEFT JOIN Example ON Job.[Job ID] = Example.[Job ID]) _
     ON Feature.[Feature ID] = Example.[Feature ID]
    WHERE (((Example.Disable)<>True))
    WITH OWNERACCESS OPTION;
    could my query be in the way somehow? I thought you could pritty much treat them like tables.
    Last edited by Matt_T_hat; May 30th, 2003 at 11:09 AM.
    ?
    'What's this bit for anyway?
    For Jono

  6. #6
    Lively Member MileOut's Avatar
    Join Date
    Nov 2001
    Location
    Glasgow
    Posts
    83
    3 Things

    1. Your line: =IIf(IsNull(Sum([FinalPrice])),0,Sum([FinalPrice])) is a tad heavy on the functions

    Wouldn't =Nz(Sum([FinalPrice])) do the same thing?

    2. The SQLhas a possible spelling mistake - you refer to a field called Qantity, and not Quantity. This may however just be a typo.

    3. If the worst comes to the worst with your Sum function then consider using the DSum() domain aggregate function.

  7. #7

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    Sorry that was a bit rude of me, thanx for the help I don't remember how exactly but the customer is a happy one now.



    BTW: Qantity was a badly named fieldname... lol
    ?
    'What's this bit for anyway?
    For Jono

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Originally posted by MileOut

    1. Your line: =IIf(IsNull(Sum([FinalPrice])),0,Sum([FinalPrice])) is a tad heavy on the functions

    Wouldn't =Nz(Sum([FinalPrice])) do the same thing?
    This is not the same. From Ephesians's post will show the reason.
    If the SUM([FinalPrice]) is equal to Null then the Access report will
    show #Error on the report.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    Originally posted by RobDog888
    This is not the same. From Ephesians's post will show the reason.
    If the SUM([FinalPrice]) is equal to Null then the Access report will
    show #Error on the report.
    I see. Thankyou I was not fully aware of this.
    ?
    'What's this bit for anyway?
    For Jono

  10. #10
    Hyperactive Member Granty's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    439
    SUM(Nz([FinalPrice], 0)) should work tho.

  11. #11

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    Originally posted by Granty
    SUM(Nz([FinalPrice], 0)) should work tho.
    Good Use of default values and data integrity checks in the first place would be the best route.
    ?
    'What's this bit for anyway?
    For Jono

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width