Results 1 to 3 of 3
  1. #1
    hjnash is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Mar 2013
    Posts
    34

    Need some help with use of Dsum command in access

    I have a small database, one table is called Spending, In this table I have a field called Spending and here I enter money spent on food for example.
    I want to run a small VBA code from the data entry form when I enter money amount into the spending control that shows the total spending in
    category called Category. Below is the code I am trying but I get an error so the syntax is wrong. I need some pointers.
    If I understand my book correctly the Dsum expression is saying this!
    Dsum fields Spending in table called Spending where field Category contains Groceries.

    In short, how do I use this tool to pull the total money in category spending and total it up.

    Private Sub Spending_AfterUpdate()


    Dim stotal As Integer
    stotal = DSum("Spending", "Spending", "Category = Groceries")
    MsgBox stotal

    End Sub

    Thanks Harry Nash
    MS access 2013

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Need text delimiters

    stotal = DSum("Spending", "Spending", "Category = 'Groceries'")

    Use # for date fields.

    I would call field Spending something else like Amount or Cost or Spent
    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
    hjnash is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Mar 2013
    Posts
    34
    Thanks June7 what I did was add the single quite around Groceries and that fixed it.
    They where not in my book.

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

Similar Threads

  1. New Record command in Access Web Form?
    By Mercator in forum Forms
    Replies: 2
    Last Post: 12-29-2012, 08:43 PM
  2. Problem with Update Command in Access
    By anunat in forum Queries
    Replies: 3
    Last Post: 06-27-2012, 03:03 PM
  3. SQL command convert into access
    By eraydin_genc@yahoo.com in forum Access
    Replies: 4
    Last Post: 12-19-2011, 12:51 PM
  4. Access command appearing in Word
    By CrankyOldGuy in forum Access
    Replies: 0
    Last Post: 01-11-2011, 11:09 AM
  5. Access 2007 Command Buttons
    By fgerald in forum Access
    Replies: 2
    Last Post: 03-05-2010, 07:09 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