sum of if statement

aman909

Registered User.
Local time
Today, 13:02
Joined
Jun 20, 2007
Messages
28
Hello,

In a form im trying to use an If statement to do calculations. What im trying to do is this,

i have 3 text boxes. One called style, quantity and sum. What i would like is when a certain style is entered, then in the some field it displays an answer from a sum.

The statement i have been using is
If Style = "Crew" Then
Sum = "Quantity*0.35"
End If

But i dont get the answer of the sum, instead i get "Quantity*0.35"
Where im i going wrong? Can anyone help me please
 
note...
you cannot sum a text box ..
a text box can contain text and numbers ie. ABC and 123

for mathmatics you need numeric fileds otherwise it all goes tits up .
g
 
I presume you really want the following
style and quantiy and Sum

now Style must have a value and quantiy must have a value and the sum of these will be the sum

now you are also probably using a access resevered field called sum - change this to totsum or calsum - anything but sum

something is slight askew ywith what youa re trying to do ...
 
Im not sure you know what im trying to do.
Style is a textbox and will contain letters. Quantity is a numeric field as well as sum.

What i need to do is, when a certain style entered such as crew, then do a calculation and display the result in the sum field. What i have tried to use is:

If Style = "Crew" Then
Sum = "Quantity*0.35"
End If
 
To restate what Gary has said:
Sum is a reserved word. Any time you use a reserved word as an object name you are going to hit problems, so change the name to something else.

Secondly, you appear to be wrapping your calculation in quote marks. This tells Access to treat what is between the quotes as text, not a formula. If you remove the quotes, it will be treated as a formula.

Finally, where have you placed this code? If you use a simple Iif statement as the basis for a calculated field in the query that your form is based on, then you don't need any VBA.
 
In other words, changing Sum to YourSum

Code:
If Style = "Crew" Then
YourSum = Quantity*0.35
End If
 

Users who are viewing this thread

Back
Top Bottom