Results 1 to 4 of 4
  1. #1
    wazniw is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    1

    Convert a positive number to negative based on another field in a Table

    Dear Friends,

    I am trying to create a table for income and expense [catergory] and would like the amount being entered into the [amount] field to have a negative or positive value on entering based on the category chosen.

    so in my table I have

    [catergory] which is chosen from a look up table ( which is either an INCOME or EXPENSE )
    [amount] which is entered in the next field ( which has to return a positive or negative value based on the catergory choosen upon entering the data)

    I would like to go one step further and indicate this negative value in red is possible in my FORM.




    Hope you can help me- as I am unable to proceed at this point.

    Thank you very much

    Last edited by wazniw; 06-01-2013 at 07:24 PM. Reason: Image of my Database structure

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    It isn't actually necessary to save the value as a negative. Can calculate the negative in a query with an IIf expression.

    IIf([Category]="Expense",-1,1)*[Amount]

    You could use conditional formatting for the color.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    On the AfterUpDate event of the Category enter me.amount = "-" & me.amount
    For the amount when negative, use conditional formatting {Field Value is.....less than 0} This is a new rule. then add the text formatting.

    Dale

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    Might want to use conditional with that code and instead of concatenation, do math:

    Me.Amount = IIf(Me.Category = "Expense", -1, 1) * Abs(Me.Amount)

    Just in case the user changes the Category. That's the problem with saving calculated data (data dependent on other data) - if not careful the data can get 'out of sync'. That's why saving calculated data is usually not a good idea. Do calculations in queries and in textboxes.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Converting negative number to positive using QBE??
    By shabbaranks in forum Queries
    Replies: 5
    Last Post: 03-23-2012, 08:57 AM
  2. Replies: 2
    Last Post: 11-22-2011, 11:45 AM
  3. Replies: 7
    Last Post: 10-26-2011, 01:47 PM
  4. Convert Negative Values to Positive
    By creativefusion in forum Queries
    Replies: 1
    Last Post: 10-21-2009, 02:47 AM
  5. Sum Of Positive Number and Negative Number
    By maysamab in forum Reports
    Replies: 1
    Last Post: 10-20-2008, 04:06 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