Solved PUBLIC FUNCTION FAILED TO WORK (1 Viewer)

Musoke Herbert

New member
Local time
Today, 15:59
Joined
Sep 8, 2021
Messages
3
Hello members am trying to Develop a public function , below but its failling to Work can u please hel

Public Function TotalPoints(StudentID As String, Class As String, Term As String, SchoolYear As Integer) As Integer

' Returns the total of points for a student in a given class in a term a year

TotalPoints = DSum("GP", "ALevelreportsQ", "StudentID = '" & StudentID & "' AND Class = '" & [Class] & "' AND Term ='" & [Term] & "' AND SchoolYear =" & [SchoolYear] & "")

End Function
 

Attachments

  • Screenshot .png
    Screenshot .png
    32.1 KB · Views: 28

Jon

Access World Site Owner
Staff member
Local time
Today, 13:59
Joined
Sep 28, 1999
Messages
7,397
Welcome to Access World! We're so happy to have you join us as a member of our community. As the most active Microsoft Access discussion forum on the internet, with posts dating back more than 20 years, we have a wealth of knowledge and experience to share with you.

We're a friendly and helpful community, so don't hesitate to ask any questions you have or share your own experiences with Access. We're here to support you and help you get the most out of this powerful database program.

To get started, we recommend reading the post linked below. It contains important information for all new users of the forum:

https://www.access-programmers.co.uk/forums/threads/new-member-read-me-first.223250/

We hope you have a great time participating in the discussion and learning from other Access enthusiasts. We look forward to having you around!
 

plog

Banishment Pending
Local time
Today, 07:59
Joined
May 11, 2011
Messages
11,646
but its failling to Work

Help us help you. There's tons of ways for something to fail to work. What does that mean in this instance--Error message, incorrect results, computer catching fire and emitting radiation over a 4 block area? How do you know it is failing?

With that said the golden rule of debugging is --- divide, isolate and conquer. You've got a lot of points of failure, narrow it down.

Remove the criteria argument (last part) from your DSUM--does it produce a result then? If not, then either the field or table name is incorrect. If so, the problem is with your criteria argument. You've got 3 criterion in there, add them back one at a time until it fails--when it does you know the culprit--then investigate further by finding out what is specifically in that variable.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:59
Joined
Sep 21, 2011
Messages
14,306
Put all your criteria into a string variable. Then you can debug.print that until you get it correct. Then you can also use it in the function.
If any of those values are not numeric, then your syntax is incorrect.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:59
Joined
May 21, 2018
Messages
8,529
Code:
Public Function TotalPoints(StudentID As String, Class As String, Term As String, SchoolYear As Integer) As Integer
  Dim Criteria As String
' Returns the total of points for a student in a given class in a term a year
  Criteria = "StudentID = '" & StudentID & "' AND Class = '" & [Class] & "' AND Term ='" & [Term] & "' AND SchoolYear = " & [SchoolYear]
  Debug.Print Criteria
  'paste back to AWF
  TotalPoints = DSum("GP", "ALevelreportsQ", Criteria)
End Function
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:59
Joined
Feb 28, 2001
Messages
27,186
One last question... where did you declare the function? Hint: If it really is to be public, it should be declared in a general module as opposed to a class module - since class modules are only available when a form or report object is open.
 

Users who are viewing this thread

Top Bottom