Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 692
  • Last Modified:

Help with MS Access Dsum.

Dear Experts
Can anybody tell why this methods are not working?
Dim  TuitionAmt, MiscAmt As Double
   
     Dim tui As String
     tui = "Tuition"
     TuitionAmt = DSum("Amount", "tblAccount", "[GCode] ='" & Parent.CODE & "' And [Category] = " & tui & "'")
     MiscAmt = DSum("Amount", "tblAccount", "[Category] Like '" & "Misc*" & "'")

Thanks
0
JaimeJegonia
Asked:
JaimeJegonia
  • 2
2 Solutions
 
dqmqCommented:
Missing single quote, try:

Dim tui As String
     tui = "Tuition"
     TuitionAmt = DSum("Amount", "tblAccount", "[GCode] ='" & Parent.CODE & "' And [Category] = '" & tui & "'")
     MiscAmt = DSum("Amount", "tblAccount", "[Category] Like '" & "Misc*" & "'")

0
 
JaimeJegoniaAuthor Commented:
Didn't work.
0
 
koutnyCommented:
There was definitely a missing single quote in your original post, as fixed by dqmq
The second statement using the DSum function could be simplified to:

 MiscAmt = DSum("Amount", "tblAccount", "[Category] Like 'Misc*'")

In other words Misc is not used as variable here but as a text string. so if you are not getting the expected results then that might be a reason.
Do you get any error messages or is it just that the code doesn't work as you would expect?


0
 
JaimeJegoniaAuthor Commented:
The fixed is:
"nz(Amount)"  - to handle null amount to zero.
The single quote of dqmq was a partial fixed. koutny simplified function also works.
 
Thank you guys.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now