FirasSHhady
Programmer
I have design a form as an Invoice with 15 row, each consist of tow comboboxes and 3 TextBoxes, txtVal, txtNum, txtPrice.
When anyone of these 3 textboxes change I wanna change the value of txtVal TextBox.
And to do that I named each controls line with line number (i.e txtVal1, txtNum1, txtPrice1, ....) and so on.
I try to make a general sub to calc the value each time one of these 3 textboxes change and passing thoes textboxes all
not just in chengend line writting this:
Sub CalcVal(Num As TextBox, Price As TextBox, Val As TextBox)
Dim txtVals(1 To 15) As Integer
Dim sum As Long
Dim tempVal As String
Dim i As Integer
'
For i = 1 To 15
Me("Val" & i) = Me("Num" & i) * Me("Price" & i)
Next
'
For i = 1 To 15
tempVal = Me("Val" & i).Value
txtVals(i) = CInt(tempVal)
Next
'
sum = 0
For i = 1 To 15
sum = sum + txtVals(i)
Next
frmInvoice.txtInvoVal = 0
frmInvoice.txtInvoVal = sum
End Sub
and in the change Event of textboxes I write:
Private Sub txtPrice2_Change()
Call CalcVal(txtNum2, txtPrice2, txtVal2)
End Sub
but I always have error meassage.
Any ideas.
When anyone of these 3 textboxes change I wanna change the value of txtVal TextBox.
And to do that I named each controls line with line number (i.e txtVal1, txtNum1, txtPrice1, ....) and so on.
I try to make a general sub to calc the value each time one of these 3 textboxes change and passing thoes textboxes all
not just in chengend line writting this:
Sub CalcVal(Num As TextBox, Price As TextBox, Val As TextBox)
Dim txtVals(1 To 15) As Integer
Dim sum As Long
Dim tempVal As String
Dim i As Integer
'
For i = 1 To 15
Me("Val" & i) = Me("Num" & i) * Me("Price" & i)
Next
'
For i = 1 To 15
tempVal = Me("Val" & i).Value
txtVals(i) = CInt(tempVal)
Next
'
sum = 0
For i = 1 To 15
sum = sum + txtVals(i)
Next
frmInvoice.txtInvoVal = 0
frmInvoice.txtInvoVal = sum
End Sub
and in the change Event of textboxes I write:
Private Sub txtPrice2_Change()
Call CalcVal(txtNum2, txtPrice2, txtVal2)
End Sub
but I always have error meassage.
Any ideas.