Calculation does not appear in userform

  • Thread starter Thread starter helmekki
  • Start date Start date
H

helmekki

Hi

I have several Textboxs in a userform
main Textbox shows the total of the values entered into textboxs

my problem is : the total does not appear in the main Textbox untill
fill in
all other Textboxs............somtimes i want to fill in only fe
textboxes, so
the total does not appear in the Textbox that shows the total......

here is the codes i used in the userform:

PHP code
-------------------
Sub MyCalc()
If IsNumeric(tot.Text) Then
If IsNumeric(txtConsu.Text) Then
If IsNumeric(txtMaint.Text) Then
If IsNumeric(txtClea.Text) Then
If IsNumeric(carmaint.Text) Then
If IsNumeric(TransM.Text) Then
If IsNumeric(machm.Text) Then

bal.Value = CDbl(tot.Value) - (CDbl(txtConsu.Value) _
+ CDbl(txtMaint.Value) + CDbl(txtClea.Value) _
+ CDbl(carmaint.Value) + CDbl(TransM.Value) _
+ CDbl(machm.Value))
End If
End If
End If
End If
End If
End If
End If
END Sub

Private Sub tot_Change()
MyCalc
End Sub
Private Sub txtConsu_Change()
MyCalc
End Sub
Private Sub txtMaint_Change()
MyCalc
End Sub

Private Sub txtClea_Change()
MyCalc
End Sub

Private Sub carmaint_Change()
MyCalc
End Sub

Private Sub TransM_Change()
MyCalc
End Sub

Private Sub machm_Change()
MyCalc
End Su
 
Lots of ways you could handle this, but here's an easy one.

Private Sub MyCalc()
Dim dTotal As Double
On Error Resume Next
dTotal = dTotal + CDbl(TextBox1.Text)
dTotal = dTotal + CDbl(TextBox2.Text)
dTotal = dTotal + CDbl(TextBox3.Text)
'change the names of the boxes above and add the rest here
On Error GoTo 0
Label1.Caption = dTotal
End Sub

Robin Hammond
www.enhanceddatasystems.com
 

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

Back
Top