Results 1 to 2 of 2
  1. #1
    sparkles is offline Novice
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    1

    select sum query

    Hello all,

    I am tearing my hair out over what should be a very simple task. I am a php developer and find access quite frustrating.

    All I want to do is to use an SQL query to find the sum of a field for all records in another table. Then take that figure and display it in a caption on my form. It should be simple and I'm sure it is but i'm struggling to find a solution, either because it is so simple or because I do not know the correct terminology to google for.

    the following code gets me the total number of recored, but i want to add up the values of 'assetvalue'
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim intResult As Integer
    Dim strSQL As String



    Set db = CurrentDb

    strSQL = "SELECT SUM(assetvalue) As RecordCount FROM dbAssets"
    Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)

    intResult = rs("RecordCount")

    rs.Close
    db.Close

    Me.assets_j = intResult


    Any help much appreciated.

  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
    I copied that code into a db, changed the table and field names and it properly gave me the sum. I wouldn't use RecordCount as an alias, since there is a property of the same name. Perhaps your copy is confused, so I'd change that for starters.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 03-23-2012, 09:20 AM
  2. Update query using iif and select
    By josh2009 in forum Queries
    Replies: 1
    Last Post: 04-23-2010, 11:33 PM
  3. Cross Tab on Select Query
    By gazzieh in forum Queries
    Replies: 1
    Last Post: 02-04-2010, 12:07 PM
  4. Add new column in a select query
    By ysrini in forum Queries
    Replies: 3
    Last Post: 02-03-2010, 06:58 AM
  5. Select query with two criteria
    By corni in forum Queries
    Replies: 1
    Last Post: 01-22-2009, 05:23 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