Trying to execute some commands after a calculate control is done

pacctono

Member
Local time
Today, 07:43
Joined
Jun 13, 2022
Messages
66
Hello, friends!

In the following image, there is a calculated field (3.303). It gives the number of records in the subform (=Count(*)). Depending on this value I want to enabled or disabled some buttons. I tied the "After Update" event on it, but it is never executed.
Capture.PNG

Please, do any of you, can give me a hint??

Thanks
 
Unfortunately after update events do not happen if the update happened by code. However the only way that can be updated is if you add a record or change a record that gets included in the count. I would try the forms after update event and the forms on current event. Make a common procedure and call that from those two events. That procedure can read the value of the count field.
 
if it is calculated then no event will fire

depends on how your form works, but look at using the form current event instead (not sure load event will have populated your calculated control) - that will fire when the form is first opened and every time the user changes a record. If you only want it to run once then use something like

Code:
Private Sub Form_Current()
Static done As Boolean


    If Not done Then
        Select Case txtCalcField
            Case Is > 1000
                'do something
            Case Is > 2000
                'do something
            Case Is > 3000
                'do something
            Case Else
                'do something
            
        End Select
        done = True
    End If


End Sub
 
Unfortunately after update events do not happen if the update happened by code. However the only way that can be updated is if you add a record or change a record that gets included in the count. I would try the forms after update event and the forms on current event. Make a common procedure and call that from those two events. That procedure can read the value of the count field.
I tried form after update event, putting some "debug.print", but it is not executed.
 
Not enough detail for us to guess what you are doing. Post your database or show complete code.
 
if it is calculated then no event will fire

depends on how your form works, but look at using the form current event instead (not sure load event will have populated your calculated control) - that will fire when the form is first opened and every time the user changes a record. If you only want it to run once then use something like

Code:
Private Sub Form_Current()
Static done As Boolean


    If Not done Then
        Select Case txtCalcField
            Case Is > 1000
                'do something
            Case Is > 2000
                'do something
            Case Is > 3000
                'do something
            Case Else
                'do something
           
        End Select
        done = True
    End If


End Sub
Because I just want to know if the value is 0 or not. I did This:
<code>
Static hecho As Boolean

If Not hecho Then
Debug.Print SinError(Me.entContarRegistros, 0)
Else
hecho = True
End If
</code>

It prints nothing.

NOTE: <entContarRegistros> is the calculated control.
 
I have never used Static :(, but you declare it, then immediately test if it is True?

Have you walked though that code?, line by line?
 
I have never used Static :(, but you declare it, then immediately test if it is True?
a static boolean defaults to false as it does if dimmed. Just as strings will default to "" and numbers to 0

You could use a global variable instead

don't know what sinerror is and you haven't said which event you are using

try stepping through the code
 
Hello, friends!

In the following image, there is a calculated field (3.303). It gives the number of records in the subform (=Count(*)). Depending on this value I want to enabled or disabled some buttons. I tied the "After Update" event on it, but it is never executed.
View attachment 104529
Please, do any of you, can give me a hint??

Thanks
I solved it using (form).Recordset.RecordCount or in my case me.Recordset.RecordCount
 

Users who are viewing this thread

Back
Top Bottom