Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    JHG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2019
    Posts
    28

    Excel Formula To Access

    I have a simple nested IF formula in excel, which I want to use in Access. I am new to Access and can not get it right although I have tried various options.


    Excel Formula
    =IF(B2>0,(+A2-B2),IF(B2=0,+A2))

    The fields in Access in relation to the columns in Excel

    Excel Column B2 = Access Field QuantityOut
    Excel Column A2 = Access Field QuantityIn

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    The Access IIf() function has the same syntax and can be nested in the same way.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    JHG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2019
    Posts
    28
    This one worked, but it does not do what I want to do. The problem is that One is compelled to put a figure in QuantityOut in order to get a value in StockOnHand

    IIf([QuantityOut]=0,0,+[QuantityIn]-[QuantityOut])

    Therefore I tried this one, which are working in Excel. I have tried to use it using the field names with the IIf formula, but it gives syntax and other errors.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    How about:

    IIf([QuantityOut]>0,[QuantityIn]-[QuantityOut], [QuantityIn])

    which seems to approximate your Excel forumula.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    JHG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2019
    Posts
    28
    Thank You,

    I appreciate this. I am going to try it. I will let you know.

  6. #6
    JHG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2019
    Posts
    28
    Thank You,

    I appreciate this. IT IS WORKING PERFECTLY. I am so grateful.

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Happy to help! This may also work:

    [QuantityIn]-Nz([QuantityOut], 0)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    JHG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2019
    Posts
    28
    Suddenly something went wrong.
    I have tried all ways to put it in, but now it does not work anymore.
    It does not want to do the calculation anymore.
    I tried putting it in directly as an expr.
    I tried to do it by adding a field in the table.
    nothing works anymore.
    Please help

  9. #9
    JHG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2019
    Posts
    28
    Quote Originally Posted by JHG View Post
    Suddenly something went wrong.S
    I have tried all ways to put it in, but now it does not work anymore.
    It does not want to do the calculation anymore.
    I tried putting it in directly as an expr.
    I tried to do it by adding a field in the table.
    nothing works anymore.


    Please help
    Sorry to bother you, but I used another expression which works as well, but not as well as the one you gave me.
    [QuantityIn]-[QuantityOut]

  10. #10
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    What syntax is failing? Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    JHG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2019
    Posts
    28
    Ok, here I tried to zip with save as on save and publish, but it keeps doing this error. Is there any other way to send the file perhaps?

    Click image for larger version. 

Name:	Capture ACCDE file Error.JPG 
Views:	12 
Size:	17.8 KB 
ID:	39316

  12. #12
    JHG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2019
    Posts
    28
    ​I am doing the following to add the code.

    IIf

    Choose Table
    Data Sheet View
    Click “Click to add” on the fields
    Choose Calculated Field
    Choose Number
    Paste IIf([QuantityOut]=0,0,+[QuantityIn]-[QuantityOut]) with “Ctrl V”

  13. #13
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    You'd want to attach an accdb, not an accde. May help to zip it first as well.

    https://www.accessforums.net/showthread.php?t=70301
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    JHG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2019
    Posts
    28
    I thought the idea of save the file to a accde was to zip it. If not can I use winrar to zip it.

  15. #15
    JHG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2019
    Posts
    28
    Ok here is a zip file of the accdb file.

    Turnkey Stock (2).zip

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Excel formula to access vba.
    By tonycl69 in forum Programming
    Replies: 2
    Last Post: 10-20-2016, 06:36 AM
  2. Replies: 19
    Last Post: 07-13-2015, 10:15 AM
  3. Replies: 41
    Last Post: 05-29-2015, 02:58 PM
  4. set excel formula from access vba
    By trevor40 in forum Programming
    Replies: 16
    Last Post: 11-26-2014, 07:32 PM
  5. How to use this formula from Excel in Access?
    By jset818 in forum Queries
    Replies: 11
    Last Post: 10-16-2014, 03:32 PM

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