ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   using class module (https://www.excelbanter.com/excel-programming/370489-using-class-module.html)

tom taol

using class module
 


my userform has a lot of textboxes.
i want to change backcolor with yellow in is focused a textbox using
class module.

*** Sent via Developersdex http://www.developersdex.com ***

Michel Pierron

using class module
 
Hi Tom,
I do not think that it is possible with a module of class. To do that, a
timer is needed; a trick of the kind:

In a standard module:
Option Explicit
Private Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long _
, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private iTimer As Long

Sub TimerStop(Optional dummy As Byte = 0)
If iTimer Then KillTimer 0&, iTimer
iTimer = 0
End Sub

Sub TimerStart(iVal&)
If iTimer Then TimerStop
iTimer = SetTimer(0&, 0&, ByVal iVal, AddressOf TimerProc)
End Sub

Private Sub TimerProc(ByVal lHwnd&, ByVal lMsg&, ByVal lIDEvent&, ByVal
lTime&)
On Error GoTo 1
Dim Ctl As Control
For Each Ctl In UserForm1.Controls
If Left$(Ctl.Name, 7) = "TextBox" Then
If Ctl.Name = UserForm1.ActiveControl.Name Then
Ctl.BackColor = &HFFFF&
Else
Ctl.BackColor = &H80000005
End If
End If
Next Ctl
Exit Sub
1: TimerStop
MsgBox Err.Number & vbLf & Err.Description, 48
End Sub

In UserForm module:
Private Sub UserForm_Initialize()
Me.TextBox1.SetFocus
TimerStart 250
End Sub

Private Sub UserForm_QueryClose(Cancel%, CloseMode%)
TimerStop
End Sub

Regards,
MP

"tom taol" a écrit dans le message de news:
...


my userform has a lot of textboxes.
i want to change backcolor with yellow in is focused a textbox using
class module.

*** Sent via Developersdex http://www.developersdex.com ***





All times are GMT +1. The time now is 11:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com