Results 1 to 12 of 12
  1. #1
    Waldo is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2011
    Posts
    10

    calculate new value in expression in query

    Hello dear people,

    I'm kinda new to access, but wish to program a little something to let the value decrease of the inventory for our business once a year. Wonder how to set up the formula in the query. What I have:

    [current value]=iif (IsNull(Year(Date())- [year of purchase]), [original value], (1-(Year(Date())- [year of purchase])/ [depreciation])* [original value])



    (the year of purchase, depreciation and original value are all values already in our database)

    Would love some help here

    Waldo
    Last edited by Waldo; 09-20-2011 at 01:01 AM.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    In design view, the way to add a calculated field is:

    DesiredName: YourCalculationHere

    Make DesiredName whatever you want, it's just what the resulting field will be named.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Waldo is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2011
    Posts
    10
    Thanks for your reply pbaldy but even with your suggestion it doesn't work

    current value: (iif (IsNull(Year(Date())- [year of purchase]), [original value], (1-(Year(Date())- [year of purchase])/ [depreciation])* [original value]))

    Where's my mistake? Do I spell out the if-else statement wrongly?

  4. #4
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Try this:


    current value: iif (Year(Date())- [year of purchase]="", [original value], (1-Year(Date())- [year of purchase])/ ([depreciation]* [original value]))

  5. #5
    Waldo is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2011
    Posts
    10
    Thank you for the suggestion but Access keeps on protesting, this time because
    "the expression contains an invalid numer of arguments' if I translate correctly...

    How should my variables be determined? As text or numeric or valuta or it doesn't matter?

    waldo

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Might depreciation be Null? Can you post a sample db with some data to test with?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Waldo is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2011
    Posts
    10
    I set the query to only select those items with an original value higher than zero, hope that is good enough.

    A link to a slimmed-down-version: http://www.box.net/shared/87poz7h38ofthn621hpx
    hope it's clear enough & hope you can help me out here

    thanks in any case for looking at it!

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post a compacted/zipped copy here? I don't like to download from unknown sites.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Waldo is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2011
    Posts
    10
    Didn't know you could upload here, in attachment.

    Waldo

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The year field isn't in there. This ran without error:

    CurrentValue: (IIf(IsNull(Year(Date())-[Aankoopjaar]),[original value],(1-(Year(Date())-[Aankoopjaar])/[depreciation])*[original value]))
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Waldo is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2011
    Posts
    10
    I really appreciate your help but I'm ashamed to say this but it still doesn't work with me when I input it in the field of the query "qrycurrent value" it keeps saying 'Invalid Syntax - Operand w/o operator'. Could you maybe post the database online with the edit in it? Would really help me a lot...!

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This returns values without error. I don't know if they're the correct values, but there is no error.

    SELECT tblinventaris.Id, tblinventaris.Categorie, tblinventaris.[original value], tblinventaris.depreciation, tblinventaris.Aankoopjaar, tblinventaris.Beschrijving, (Year(Date())-[aankoopjaar]) AS verschiljaar, tblinventaris.Code, (IIf(IsNull(Year(Date())-[Aankoopjaar]),[original value],(1-(Year(Date())-[Aankoopjaar])/[depreciation])*[original value])) AS CurrentValue
    FROM tblinventaris
    WHERE (((tblinventaris.[original value])>"0"));
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 12-12-2010, 05:03 PM
  2. Replies: 1
    Last Post: 12-10-2010, 11:03 AM
  3. how to calculate Percent in an update query?
    By newtoAccess in forum Queries
    Replies: 4
    Last Post: 11-23-2010, 10:11 AM
  4. Calculate average in a query
    By srbooth in forum Queries
    Replies: 1
    Last Post: 02-20-2010, 09:41 AM
  5. Calculate problem in query
    By crujazz in forum Queries
    Replies: 2
    Last Post: 06-15-2009, 08:03 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