By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,952 Members | 1,592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,952 IT Pros & Developers. It's quick & easy.

DSum function issue with conditions / criteria expressions

P: 46
Hi community experts,

I am having an isue with Dsum function that is used to count the total number for a particular field (intake) at the textbox afterupdate event with condition/ criteria (subject). Below is the scenario in details.

What I need to do is summing the intake corresponding to what is selected from the dropdown combo box. For instance if the user choose maths in the combo box, the total no of intake should be displayed in the subject textbox as 150.

May I knw hw can that be achieved and whether I am in the correct direction? I have provided the necessary details that is required for this scenario. Tks for advice, code snippets.

Form controlSource = Registration Table

Expand|Select|Wrap|Line Numbers
  1. Registration Table design view
  2.  
  3. SerialCode        autonumber        primary key
  4. subject             text                            
  5. intake               number
  6.  
  7. Registration Table view
  8.  
  9. SerialCode         Subject             Intake
  10. 1                       maths               100                        
  11. 2                       science             100        
  12. 3                       maths                 50      
  13. 4                       science               50         
  14. 5                       english              100              
  15.  
  16. Form design view
  17.  
  18. Subject            unbounded combo box
  19. Subject            unbounded textbox
  20. Intake              unbounded textbox
Code

Expand|Select|Wrap|Line Numbers
  1. Private Sub Subject_AfterUpdate(Cancel As Integer)
  2. Dim sum As Variant
  3. sum = DSum("Intake", "Registration", "subject = '" & Me.ComboSubject.Column(0) & "'")
  4. Me.Requery
  5.  
  6. End Sub
Feb 6 '07 #1
Share this Question
Share on Google+
3 Replies


NeoPa
Expert Mod 15k+
P: 31,758
Your code doesn't seem to know what the control is named :
Private Sub Subject_AfterUpdate but later on :
Me.ComboSubject.Column(0)
Also, after setting up the variable Sum it doesn't seem to use it anywhere.
Feb 7 '07 #2

P: 46
tks for the reply. issue has been solved


Your code doesn't seem to know what the control is named :
Private Sub Subject_AfterUpdate but later on :
Me.ComboSubject.Column(0)
Also, after setting up the variable Sum it doesn't seem to use it anywhere.
Feb 7 '07 #3

NeoPa
Expert Mod 15k+
P: 31,758
You're welcome, and thanks for letting us know.
Feb 7 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.