Some simble VB help please

A

Alice Jones

Hi Im creating a small DB and I would like to make it just a little more
functional.

My VB knowledge is zero

Anyhow I have 3 number boxes, if I put a num in box 1 and a num in box 2, I
would like it to total in box 3...simple eh....when you know how.

Thanks in advance to anyone who can supply the answer.

Ta
 
A

Alex White MCDBA MCSE

the way I would go about it is

if you want to use the events off the textboxes e.g. just exiting the
textbox and the calculate happens

Sub Calculate()
If IsNumeric(Me.Text0.Value) And IsNumeric(Me.Text2.Value) Then
Me.Text4.Value = Val(Me.Text0.Value) + Val(Me.Text2.Value)
End If
End Sub

Private Sub Text0_Exit(Cancel As Integer)
Call Calculate
End Sub

Private Sub Text2_Exit(Cancel As Integer)
Call Calculate
End Sub

in the above example Text0, Text2 are the input textboxes and Text4 gets the
result.
 
D

Douglas J Steele

Even better may be to create a query that has a computed field:

SELECT Field1, Field2, [Field1] + [Field2] AS Field3
FROM MyTable

Use that query as the recordsource for the form, and the arithmetic will
automatically be done.
 
Top