IF STatement

coolcatkelso

Registered User.
Local time
Today, 00:42
Joined
Jan 5, 2009
Messages
279
Hiya guys

I was given this code before -

Code:
If Me.Amount Due.Value = 0 Then
     Me.Paid.Value = -1
End If

but it doesn't seem to function..
Any help?
________
Beautyxdoll
 
Last edited:
Can you post a link to where you got it from?
 
It may be because one of your controls has a space in it's name, try;
Code:
If Me.[B][COLOR="Red"][[/COLOR][/B]Amount Due[COLOR="Red"][B]][/B][/COLOR].Value = 0 Then
     Me.Paid.Value = -1
End If
 
Hiya, cheers for the reply

I managed to get it working on a practice form wth the same names, so I'm thinking that it could be because the field its applied is calculated?
________
FREE WORDPRESS THEMES
 
Last edited:
The names are like this

Private Sub Payments_AfterUpdate()
If Me.Total_Payments.Value >= 0 Then (Greater than 0)
Me.Paid.Value = -1
End If
End Sub
________
The cigar boss
 
Last edited:
>>If Me.Total_Payments.Value >= 0 Then (Greater than 0)<<

That’s incorrect.

Can you post a link to where you got it from?
 
Ah ok

I got one on here which worked but not on calclated fields tho and the other one
came from a guy I phoned lol sorry

So what would it need to be?

I went for the Greater Than to see if it would work.. but it didn't

So the correct version would need to be like this

Private Sub Amount_Due_AfterUpdate()
If Me.Amount_Due.Value = 0
Me.Paid.Value = -1
End If
End Sub

But that doesn't work on the calculated field tho

Heres the calculation I'm using in the field for Amount_Due
=[Order Total]-nz([Payments])
________
Corvette mako shark (concept car)
 
Last edited:
>>If Me.Total_Payments.Value >= 0 Then (Greater than 0)<<

Was incorrect for two reasons.

1. the part (Greater than 0) is a comment.
2. the part (Greater than 0) is incorrect because it should be Greater than or equal to 0

What does Me.Paid refer too?
Is it a value stored in a table?
 
Me.Paid is a checkbox on the table

If the Amount Due is ?0.00 then place a tick in the Paid box then when I run a report, I can filter on the YEs/No for unpaid accounts
________
MILF XXX
 
Last edited:
Paid is the result of a calculation.
Generally speaking, we should not store the results of a calculation.
If we follow that general recommendation we have no need for the code.

I just overcame one of your problems by getting rid of the code. ;)
 
Well its not the resuilt of the calculation. The calculation is the Amount Due field.. All the paid box is, is a yes . no If the Amount due is ?0 then True / Yes

Then I can show this on the customer form and filter out l8r on the Paid box
________
DICK S
 
Last edited:
>>Well its not the resuilt of the calculation.<<

From what you have described, yes it is.
The Value of the Table field Paid is intimately tied to [Order Total]-Nz([Payments]).
 
Incorrect.

Your Form should be based on a Query.
In that Query create a new Field called Paid.
Paid derives its calculated value from [Order Total]-Nz([Payments]).
This then leaves the Paid Query field as either zero or not zero.
The calculated Paid value is then False if zero and true for any other value.
That then leads to the idea that the Paid field, in the Query, is incorrectly named.
Meaning it should be called AmountOutstanding because it could also be negative.
Only when AmountOutstanding is zero could is reasonably be called Paid because a refund may also apply.
 
If the amount due is calculated, the Amount_Due_AfterUpdate()event will not automatically fire. BeforeUpdate/AfterUpdate events never fire if their values are populated thru code, such as a calculation. They pnly fire if data is physically entered. For it to fire you'll have to explicitly call the sub, probably right after the code that does the calculation.
 

Users who are viewing this thread

Back
Top Bottom