Results 1 to 3 of 3
  1. #1
    pthomp52 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2021
    Posts
    7

    Calculated fields based on If statement


    I have a table in a database where I need to make a calculated field for VAT based on the criteria of another field. I have an amount field, a cash/invoice field which is filled from a combo box in a form with only choice Cash or Invoice, and I need the VAT to look at the cash/invoice field and if it says cash then return a zero and if not then calculate 20% of the amount field.
    I can't seem to be able to get it to look up what is in the cash/invoice field to do this

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    First, don't use actual calculated fields in the table!!! You can achieve this in your queries.


    I'd suggest that the cash/invoice field actually be a yes/no field. For example [IsInvoice]. You can still use a combobox in your form.

    Behind the scenes in M$Access the Yes = -1 and No = 0. So you could calculate VAT = -0.2*[IsInvoice]*[amount field]

    I've attached an example DB demonstrating my method as well as the IIF statement you've asked for.

    Also, I use integer fields instead of actual yes/no fields per allen browne's advice here: http://allenbrowne.com/NoYesNo.html


    Attached Files Attached Files

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,944
    I'd have to disagree in this case, as one would have to look up the VAT rate for that particular date and then apply.?

    Depends if your combo is read from a table?
    If it was and 1 was Cash and 2 was Invoice, then
    Code:
    Me.txtVAT = IF(Me.Combo = 1,0,Me.txtAmount * Me.CurrentVAT)
    Me.CurrentVAT would be the current VAT rate and being used like that now, would be 0.2

    If it was a value list, then just check for "Cash" instead

    HTH
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 3
    Last Post: 03-08-2019, 03:25 PM
  2. Replies: 7
    Last Post: 10-11-2016, 06:17 AM
  3. Replies: 12
    Last Post: 08-25-2014, 07:32 AM
  4. Replies: 12
    Last Post: 10-01-2013, 12:59 PM
  5. Query Date Range Based on Calculated Fields
    By wilsoa in forum Queries
    Replies: 6
    Last Post: 03-08-2012, 02:41 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