Results 1 to 12 of 12
  1. #1
    akrasodomski is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2012
    Posts
    10

    Basic Subtraction in Access


    Hi there,

    I'd like to have an ticker at the top of my Form that subtracts the number of PAID invoices (records with a YES in the paid column) from the number of TOTAL invoices (records), thus leaving me with a number of UNPAID invoices.

    At the moment, I am using a Yes/No under the heading 'Paid' to determine which invoices are paid and which are not. Is there a way this subtraction can done?

    Thanks,

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,593
    If the paid invoices have a 'Yes' in the 'Paid' column and the unpaid invoices don't have 'Yes' - you can just run a query something like this:
    Code:
    Select Count(Paid)
    From [YourTableName] 
    Where Paid <> 'Yes';
    To get your count.
    You can do that using VBA code that is triggered in an Event of your choice on the Form and then get that number out of the SQL and onto your Form.

    I don't totally get how you are wanting the number of unpaid invoices to be displayed on your Form but if you can give me a few more details, I might have a couple of suggestions.

  3. #3
    akrasodomski is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2012
    Posts
    10
    Quote Originally Posted by Robeen View Post
    If the paid invoices have a 'Yes' in the 'Paid' column and the unpaid invoices don't have 'Yes' - you can just run a query something like this:
    Code:
    Select Count(Paid)
    From [YourTableName] 
    Where Paid <> 'Yes';
    To get your count.
    You can do that using VBA code that is triggered in an Event of your choice on the Form and then get that number out of the SQL and onto your Form.

    I don't totally get how you are wanting the number of unpaid invoices to be displayed on your Form but if you can give me a few more details, I might have a couple of suggestions.

    I've fallen at the first hurdle: http://i44.tinypic.com/f24j8k.jpg

    Why can't it find my table?

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Why couldn't you use =DCount([Paid],sourcetable,[paid]=0) as the controlsource of a textbox?

  5. #5
    akrasodomski is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2012
    Posts
    10
    Quote Originally Posted by RayMilhon View Post
    Why couldn't you use =DCount([Paid],sourcetable,[paid]=0) as the controlsource of a textbox?
    Ray,

    I just got a #Name? Error when I tried that as the controlsource. Why is it not finding the value?

  6. #6
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Did you include the actual table name where I put sourcetable? Since I don't know your table structure. the syntax of the function is Dcount(fieldname,tablename,criteria)

  7. #7
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    You need to be specific and name it correctly

    dcount works as such
    for numbers
    =dcount("[Field_name]","[Table_name]","[where_condition]="&[field])
    for strings
    =dcount("[Field_name]","[Table_name]","[where_condition]='"&[field]&"'")
    for dates
    =dcount("[Field_name]","[Table_name]","[where_condition]=#"&[field]&"#")

    Worth reading:
    http://allenbrowne.com/casu-07.html

    We can't write it completely for you because you never provided the table name.

    And you could do a double calculation

    =DCount([Paid],sourcetable,[paid]=0)-DCount([Paid],sourcetable,[paid]<>0)

  8. #8
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Just looked at the actual syntax from Microsoft and my definition above is different because of the way I've always used it. The true Syntax from microsoft is DCount(Expression,domain,criteria).

  9. #9
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    R Badger much better explanation than mine. Thanks

  10. #10
    akrasodomski is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2012
    Posts
    10
    Quote Originally Posted by R_Badger View Post
    You need to be specific and name it correctly

    dcount works as such
    for numbers
    =dcount("[Field_name]","[Table_name]","[where_condition]="&[field])
    for strings
    =dcount("[Field_name]","[Table_name]","[where_condition]='"&[field]&"'")
    for dates
    =dcount("[Field_name]","[Table_name]","[where_condition]=#"&[field]&"#")

    Worth reading:
    http://allenbrowne.com/casu-07.html

    We can't write it completely for you because you never provided the table name.

    And you could do a double calculation

    =DCount([Paid],sourcetable,[paid]=0)-DCount([Paid],sourcetable,[paid]<>0)

    I don't understand how - with all this help - I still can't do it. My table appears to be called RecievedInvoices, but that still throws up an error (note: the typo is in the original).


    =DCount([Paid],sourcetable,[paid]=0)-DCount([Paid],sourcetable,[paid]<>0)[/QUOTE]

    The 'Paid?' column has a ? and is a yes/no.

    Perhaps if you write it I can work back from the answer to work out what I'm doing wrong. Appreciate the effort, thanks.

  11. #11
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Why are you using a wildcard character in your fieldname. MS Access has 2 wild card characters the * and ? for example "*test*" would return any value with test anywhere in the string. example "this is a test" would be true "?test?" would return any value that is length of 6 with any single character before or after "test" example "This is a test" would be false "atest1" would be true The * is a wildcard for a string the ? is a wildcard for a character.

  12. #12
    RagJose is offline Seasoned user
    Windows XP Access 2002
    Join Date
    Apr 2012
    Location
    Brazil
    Posts
    42
    Please note Dcount arguments are all String type as R_Badger illustrated. Therefore, the control in your form should have a source like

    =DCount("[Paid]", "[RecievedInvoices]", "[Paid]<>'YES' ")

    The above assumes the "Paid" field holds the string "YES" when the invoice has been paid, and something else otherwise. If not, adapt the condition accordingly.

    HOWEVER...

    if "something else" can be a Null, the above won't work because DCount ignores records whose count field is Null, and comparisons with Null yield Null instead of True/False. Use instead:

    =DCount ("*", "RecievedInvoices", "IsNull [Paid] or [Paid]<>'YES' ")
    Last edited by RagJose; 04-19-2012 at 06:20 AM. Reason: Second thought

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

Similar Threads

  1. date subtraction in query
    By mejia.j88 in forum Queries
    Replies: 1
    Last Post: 03-29-2012, 02:28 PM
  2. Calculation in Code Builder for Sum & Subtraction
    By braveali in forum Programming
    Replies: 19
    Last Post: 03-07-2012, 12:32 AM
  3. Replies: 2
    Last Post: 02-02-2012, 12:18 PM
  4. subtraction between records
    By JJCHCK in forum Programming
    Replies: 5
    Last Post: 10-11-2011, 12:57 AM
  5. Basic Access Help
    By alex2300 in forum Access
    Replies: 2
    Last Post: 06-07-2011, 09:42 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