Unable to use the Sum function in access visual basic

Anonymous
2016-05-14T19:49:56+00:00

Have a vb program which i am trying to use the Sum function but am unable. Compiler says not defined, Think there is a reference i need to a library. Any one got a idea? TIA

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2016-05-14T20:07:55+00:00

    Sum is not a VBA function. It is an aggregate function that you can use in queries and in SQL statements. And it is a worksheet function in Excel.

    Can you provide some details about how you want to use Sum in Access VBA?

    0 comments No comments
  2. Tom van Stiphout 40,091 Reputation points MVP Volunteer Moderator
    2016-05-14T20:30:20+00:00

    Maybe you really wanted to use the DSum function. Check it out in the VBA help file.

    0 comments No comments
  3. Anonymous
    2016-05-16T02:29:54+00:00

    Maybe u can help me understand the dsum method:

    I have table "attendance" which has fields of "d1", "d2", ...

    I am trying to sum all the entries in "d1" which can be 70 or more

    Some of the entries in "d1" are blanks (never had any thing entered or a text number)

    here is part of the program:

        Dim Nsum As Integer, Isum As Integer, Csum As Integer, Iattendance As Integer

        Dim rstAttend As Recordset

        With rstAttend

        Set rstAttend = dbsDatabase.OpenRecordset("attendance", dbOpenDynaset)

        Nsum = 0

        Isum = 0

        For I = 1 To 36

        strTemp = "d" & I

        Csum = DSum(rstAttend.Fields("d" & I), "attendance")

    When i execute the pgm i get: improper use of null or some thing like that, any idea what i am doing wrong? TIA

    0 comments No comments
  4. Tom van Stiphout 40,091 Reputation points MVP Volunteer Moderator
    2016-05-16T02:54:38+00:00

    d1, d2, ... d36: that sounds like a likely violation of relational database design rules. Can you please post a Relationships diagram of the most important tables? I'm assuming you are interested in doing things the way Access (and every other RDBMS) was designed to be used.

    0 comments No comments
  5. Anonymous
    2016-05-17T00:51:31+00:00

    I think u have me there. Have no idea what a relational db is. 

    here is what a design view of what table attendance looks like:

    attendance (table name)

    fields:

    roster name d1 d2 d3 d4 ...

    eg:

    1         sue    1         1        

    2         ed            1

    3         sam                   1

    sue attended on day1 & day3

    ed   attended on day2

    sam attended on day4

    ...

    class days (table name)

    fields:

    startday classday1 classday2 classday3 ...

    students(table name) 

    fields are about info of the student name, address ...

    BTW I thought dsum would save me writing a for loop but i am over my head. Started with fortran do loops in 1956 & hard to teach an old dog new tricks :-)

    0 comments No comments