How to SUM values using VBA

Mr.K

Registered User.
Local time
Today, 16:42
Joined
Jan 18, 2006
Messages
104
I have a frmMain with field AmountAvailable and sbfDetails with field AllocatedPayments. How can show a warning MsgBox when the SUM of AllocatedPayments is larger then the AmountAvailable?
I'm not sure how to replicate the SUM function in VBA (do I run SQL statement that uses SUM?) and how I pass the value to a variable so I can comapre it in an IF statement with the AmountAvailable.
Also, how do I reset the value of the AllocatedPayment and don't allow the user to continue (save the value) if the last value he entered caused the sum to exceed the AmountAvailable? Should I run my code in Validation property rather then on AfterUpdate?

I appreciate if someone could address all the above questions becasue then I could figure out some other things on my own that are not mentioned in this post, but which make me confused (e.g. assigning a single result from SQL statement executed with VBA - do I always have to use "rst.something" and then field(0) even when I know the SQL will return single value? Or am I doing it the long way?).

Big thanks for any response.
 

Users who are viewing this thread

Back
Top Bottom