sum of two fields in a form

V

viren

hi

I have two fields [value 1] and [value 2] that are based on a set value
action macro. there are 3 checkboxes on each repair that i carry out on a
component. if i click on any of these check boxes it gives me a value
associated by means of the set value action.. i need to add these two
values to give a running total based on what i have clicked.
the formula i use is =Nz([value1],0)+Nz([value2],0)
eg: if value 1 is 50 and value 2 is 100 the total should be 150. but the
total it shows on the form is 50100. doesnt make sense. please help!!!!!!!
 
A

Arvin Meyer MVP

You would do much better with code. It seems that your code is concatenating
the 2 values instead of adding them. Make sure that both fields are numeric
and do something like:

Private Sub Value_1_AfterUpdate()
If IsNumeric(Me.[Value 1] Then
If Len(Me.[Value 2] & vbNullString) > 0 Then
Me.[Total] = Nz([value1],0)+Nz([value2],0)
End If
End If
End Sub

Do the same thing for the [Value 2] text box changing the appropriate names.
As far as a running total, you'll need to do that in a report.
 
V

viren

Thank you, It works....

Arvin Meyer MVP said:
You would do much better with code. It seems that your code is concatenating
the 2 values instead of adding them. Make sure that both fields are numeric
and do something like:

Private Sub Value_1_AfterUpdate()
If IsNumeric(Me.[Value 1] Then
If Len(Me.[Value 2] & vbNullString) > 0 Then
Me.[Total] = Nz([value1],0)+Nz([value2],0)
End If
End If
End Sub

Do the same thing for the [Value 2] text box changing the appropriate names.
As far as a running total, you'll need to do that in a report.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


viren said:
hi

I have two fields [value 1] and [value 2] that are based on a set value
action macro. there are 3 checkboxes on each repair that i carry out on a
component. if i click on any of these check boxes it gives me a value
associated by means of the set value action.. i need to add these two
values to give a running total based on what i have clicked.
the formula i use is =Nz([value1],0)+Nz([value2],0)
eg: if value 1 is 50 and value 2 is 100 the total should be 150. but the
total it shows on the form is 50100. doesnt make sense. please
help!!!!!!!
 

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