Hi. No error message, just not doing what I want it to
do. I have been able to walk through the code to see
what's going on. I have 2 problems.
1) curTotal = Nz(DSum("BucksNumber", "BucksMember",
strWhere), 0) + Nz(DSum("ITABucks", "Shifts", strWhere),
0) is giving me "17" for every ContactID. Shifts.ITABucks
for ALL records does equal 17, which excludes any
BucksNumber. Maybe it's my setup? BucksMember contains
ContactID (this is how I assign the felxible BucksNumber).
The ITABucks are associated with Shifts that tie to
Volunteering that tie to Event, so that Event table
contains ContactID, VolunteeringID and ShiftID. Anyway to
fix curTotal to account for that?
2) yes, I would like curTotal to not count the BucksNumber
I'm trying to add on the fly. I can't figure out how to
do that and then compare it to the current BucksNumber.
Any suggestions?
Here's what it looks like now (at least the <-30 part
works!). Thanks for your help, Stephanie
Private Sub BucksNumber_BeforeUpdate(Cancel As Integer)
'Use two DSum() expressions to get the total, e.g.:
Dim strWhere As String
Dim curTotal As Currency
Dim strMsg As String 'MsgBox message.
Dim bWarn As Boolean 'Flag to warn user.
strWhere = "[ContactID] = " & Nz([ContactID], 0)
curTotal = Nz(DSum("BucksNumber", "BucksMember",
strWhere), 0) + Nz(DSum("ITABucks", "Shifts", strWhere), 0)
If ((curTotal) - (Me!BucksNumber)) < (Me!BucksNumber)
Or (Me!BucksNumber) < -30 Then
Cancel = True
strMsg = strMsg & "Member does not have enough
Bucks to 'cash in' that many." & vbCrLf
End If
Call CancelOrWarn(Cancel, bWarn, strMsg)
End Sub
-----Original Message-----
Error message?
Wrong results? Do you need to change the Criteria of one of the lookups so
that it sums the *other* records (excluding the current one)?
I didn't follow the Abs() bit.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Thanks! Now you can see how terrible I am at coding.
I added this code (see below) to the form where I'm
entering "free-form" bucks. This form is on my main
Contacts form, so I can't just enter the bucks in
the "bucks form" and step through the code (or I wouldn't
have a ContactID). My part of code isn't working
(surprise). I'm trying to get the total bucks, compare it
to the BucksNumber being entered in the field to make sure
there are enough bucks earned to justify the cash-in, and
make sure that they can't cash in more than 30. Thanks
for your your help! Stephanie
Private Sub BucksNumber_BeforeUpdate(Cancel As Integer)
'Use two DSum() expressions to get the total, e.g.:
Dim strWhere As String
Dim curTotal As Currency
Dim strMsg As String 'MsgBox message.
strWhere = "[ContactID] = " & Nz([ContactID], 0)
curTotal = Nz(DSum("BucksNumber", "BucksMember",
strWhere), 0) + Nz(DSum("ITABucks", "Shifts", strWhere), 0)
If Abs(curTotal) < (Me!BucksNumber) Or curTotal < -30
Then
Cancel = True
strMsg = strMsg & "Member does not have enough
Bucks to 'cash in' that many." & vbCrLf
End If
End Sub
-----Original Message-----
Use two DSum() expressions to get the total, e.g.:
Dim strWhere As String
Dim curTotal As Currency
strWhere = "[MemberID] = " & Nz([MemberID], 0)
curTotal = Nz(DSum("Bucks", "Table1", strWhere), 0) +
_
Nz(DSum("Bucks", "Table2", strWhere), 0)
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
in message
Hi. I have a field that can be positive or negative-
Members earn "bucks" by volunteering and then cash them
in to defray cost of renewing. It's a little bit more
complicated because there are 2 ways of earning bucks (2
fields in different tables).
I just wrote a union query to combine the bucks. For my
report, I have a conditional that allows the user to
pick
the Member's name so I can see a running total of all
bucks for that Member.
In the form where I assign positive/negative bucks- if
I'm assigning negative bucks, I'd like to check that the
running total of bucks supports that negative entry (so
that bucks total for that Member doesn't go negative,
and
also that the negative entry isn't bigger than -30.
Can I use what I've already created? Do I need to write
code to check this (except total bucks by member isn't a
field and I'm not good a coding)? Any suggestions?
Thanks for your help, Stephanie