Solved PUBLIC FUNCTION FAILED TO WORK

Musoke Herbert

New member
Local time
Today, 06:34
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: 64
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!
 
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.
 
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:
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
 
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

Back
Top Bottom