after/before update txtbox

benjamin.weizmann

Registered User.
Local time
, 20:06
Joined
Aug 30, 2016
Messages
78
hi , I have this sub:

Private Sub mach_2_AfterUpdate()
If Me.ex2 .value= 99999 And Not Me.mach_2.Value = 0 Then
If msgzeropro = 0 Then
Me.mach_2.Value = 0
Exit Sub
Else
Me.ex2.Value = msgzeropro
End If
End If
Call colordec(2)
End Sub

when msgzeropro and colordec are functions
this sub create kind of loop

cause in the first .. the user update the txtbox and call sub((1))
and in accordance condition , the sub update the textbox and call itself ((2))

how can I avoid ((2))??

I thought some ideas like static variable (but I have some txtbox with same sub) - so, I can not wait to hear your creativeness

:)

thanks
Ben

thanks u
 
Add a Boolean variable to the procedure e.g blnFlag

Set the value true when the value is updated.
Add a further condition so the sub only runs when blnFlag is False

Remember to reset the value to false after use.
 
Add a Boolean variable to the procedure e.g blnFlag

Set the value true when the value is updated.
Add a further condition so the sub only runs when blnFlag is False

Remember to reset the value to false after use.


sorry I don't think it 's the solve in this case..
or more exactly, maybe I don't know to operate it

I'll give u the full details :


Private Sub mach_1_AfterUpdate()

If Me.ex1.value = 99999 And Not Me.mach_1.Value = 0 Then
If msgzeropro = 0 Then
Me.mach_1.Value = 0 (***)
from now, everytime the user updates mach_1 I want this sub to occur
but not for this assign (***)

Exit Sub
Else
Me.ex1.Value = msgzeropro
from now, the sub will not be called and it's ok
End If
End If

Call colordec(1)
End Sub






thanks
 
1. It would be better if you told us in words what you want to do. It makes it easier for us to identify logic errors in the code if we know what you think you are trying to do.
2. When you post code, always use the # tag so that indentation is maintained. Left aligned code is harder to read than it needs to be.
3. You almost certainly want to move this code to the Form's BeforeUpdate event. Whenever you have validation that involves more than one control, it gets too confusing to do it in one of the control events because you always have to verify that the other necessary values have already been entered. At least in the Form's BeforeUpdate event, everything that the user is going to enter is already entered. Plus, you can prevent the record from being saved if you find an error by using --- Cancel = True followed by Exit Sub.
 

Users who are viewing this thread

Back
Top Bottom