If then Else

T

TL

I have written the following If then else statement for a form. It makes
sure that 3 fields in a form add up to a seperate field before I go onto
another procedure. No matter what I do, it keeps skipping over this
statement. I can make sure that the fields add up to [Form].[Text41] one
time and not add up to it another and it still skips it.

Is there a better way of doing this??

If [Form].[Food Cost.SumofTrnValue] + [Form].[Pack Cost.SumofTrnValue] +
[Form].[Labor Costs.TrnValue] + [Form].[Freezing Costs.TrnValue] +
[Form].[Overhead Costs.TrnValue] <> [Form].[Text41] Then
MsgBox "The sum of Food Cost, Pack Cost, Labor Cost, Freezing Cost and
Overhead Cost does not add up to the Total Dollars Field", 0, "Addition
Error"
Cancel = True
frm("Text41").SetFocus
End
End If


Thanks!!

Tim
 
E

Eric

Hey Tim,

You should sum up your results into a variable, then use
that variable to do your comparison with [Form].[Text41].
Ex.
-----------------------
Dim iSomeInt As Integer

iSomeInt = [Form].[Food Cost.SumofTrnValue] + [Form].
[Pack Cost.SumofTrnValue] + [Form].[Labor Costs.TrnValue]
+ [Form].[Freezing Costs.TrnValue] + [Form].[Overhead
Costs.TrnValue]

If iSomeInt <> [Form].[Text41] Then
...
Else
...
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top