• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VB 'BeforeUpdate' Procedure code failing

Hello all,
Unable to get through a "BeforeUpdate" procedure for a field that is calculated in vb form.
The user form has three amount fields (user entered) - txtAmount01, txtAmount02, txtAmount03. The realtime summation of these three is expected to be updated in field "txtGross". Reason for using "BeforeUpdate" - so that the txtGross field updates real-time as and when the user enters amounts in each of the three fields.
The code below is not going through, with error as "Procedure declaration does not match description event or procedure having same name". I have ensured that there is no other procedure with similar name.

Where am I going wrong ? Appreciate support, Thanks!

Code:
Private Sub txtGross_BeforeUpdate(Calculate As Double)
    If (Not IsNull("txtAmount01")) Then
    txtGross.Text = Val(txtAmount01.Text) + Val(txtAmount02.Text) + Val(txtAmount03.Text)
    Else
    MsgBox ("At least one amount must be more than zero")
    End If
    
Calculate = True

Me.txtGross.Value = Format(Me.txtGross.Value, "#,##,##0.00")
End Sub
 
Sudhir Prabhu
Calculate As Double ... hmm?
What is Your Calculate-value in the beginning?
and
... later You set it 'True'

or
Have You checked is there other same name Procedure?
 
Calculate value is amount (without currency) with two places decimal; hence used double. To begin with the default value is set at 0.00.

Yes, I double checked on same name procedure - ruled out.
 
for same field - txtGross.
The tag 'Calculate = True' is part of the syntax for BeforeUpdate procedure, as I understand. By the way, I did try setting it as false, but that did not make any impact on result.
 
I can see only one part of Your codes ...
but
if Calculate is amount (as money)
as well as Your bank account would have something ...
and few moments later
You say that (Your bank account) ... it's TRUE .. or .. FALSE ...
do it mean that You have money or not?

wow?

Have You tried to run that row-by-row?
Can You upload whole code with file which works (or should work)?
 
Sudhir Prabhu
... or
1) add ' -mark (~skip line) to the 1st mark in every line of Your code.
2) run Your code
3) if works then
take one ' -mark away and run again
else
replace previous
endif
4) repeat steps from 2 until You've found Your challenge
..
eg why there is line Calculate = True ?
 
Back
Top