Report Offensive Message

While working this is very very inneficient
Hello Peter,

This is a very nice trick (which you can use in many ways). But there a catch here, its works but it's slow.

2 reasons behind this.

1st - You're accessing the ctl in late-binding. It is always slower and moreover more error prone as the compiler cannot check if the method or attribute really exists

2nd - The TypeOf operator does pretty cool stuff in the back. Cool but slower too.

A faster and safer implementation of the code in your article would be:

Dim c As Control
Dim txt As TextBox

For Each c In Me.Controls
On Error Resume Next
Set txt = c
On Error GoTo 0
If Not txt Is Nothing Then
txt.ForeColor = vbRed
End If
Next


Regards!
Posted by myrdhrin
27th Jan 2006