Probably not the best title, but it will be better with this exemple.
Here's a function inside a userform
of a checkbox
. I was trying to change the font to bold
before the call to SelectAlldtList
(which takes a few seconds to do).
What is happening is that the font doesn't change until after the SelectAlldtList
is finished.
Private Sub CheckBoxAllDirectionTerritoriale_Click()
If Me.CheckBoxAllDirectionTerritoriale.Value = True Then
CheckBoxAllDirectionTerritoriale.Font.Bold = True
Call SelectAlldtList
Else
CheckBoxAllDirectionTerritoriale.Font.Bold = False
Call UnselectAlldtList
End If
End Sub
If I add a Wait
of 6 milliseconds, the behavior is the one I want.
If I add a Wait
of 5 milliseconds, the behavior is the same as without the Wait
at all.
Private Sub CheckBoxAllDirectionTerritoriale_Click()
If Me.CheckBoxAllDirectionTerritoriale.Value = True Then
CheckBoxAllDirectionTerritoriale.Font.Bold = True
Application.Wait (Now + 0.000006)
Call SelectAlldtList
Else
CheckBoxAllDirectionTerritoriale.Font.Bold = False
Application.Wait (Now + 0.000006)
Call UnselectAlldtList
End If
End Sub
Why is that? Is it something like without the Wait
, SelectAlldtList
is called before having time to bold
and taking all the ressources?
While I'm at it, would there be a better way to do this? Some kind of synchronization?