Microsoft KB Archive/210187

= ACC2000: How to Change Active Control Background Color with Timer Event =

Article ID: 210187

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210187



Advanced: Requires expert coding, interoperability, and multiuser skills.



SUMMARY
This articles demonstrates a method that you can use to change the background color of the active control on a form. This method will change the background color of any active control that supports the BackColor property.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.



MORE INFORMATION
To create the method that changes the background color of the active control on a form, follow these steps.

CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb or perform these steps on a copy of the Northwind database.  Open the sample database Northwind.mdb. In the Database window, click Modules under Objects, and then click New.  In the Declarations section of the module, type the following line: Global myctrname as String  Save the module as Module1, and then close the module. Open the Customers form in Design view.  Set the OnTimer property of the Customers form to the following event procedure: Private Sub form_Timer

Dim lngYellow As Long, lngWhite As Long On Error GoTo Errhandler lngYellow = RGB(255, 255, 0)    'Set lngYellow variable for 'yellow color. lngWhite = RGB(255, 255, 255)   'Set lngWhite variable for white 'color.

If Screen.ActiveControl.Name <> myctrname Then ' If active ' control not ' equal to                                                   ' myctrname do                                                    ' next line. Me(myctrname).BackColor = lngWhite           ' Set myctrname ' variable to white ' BackColor. Screen.ActiveControl.BackColor = lngYellow   ' Set active color ' BackColor to                                                 ' yellow. myctrname = Screen.ActiveControl.Name        ' Set myctrname ' variable to                                                 ' active control ' name. End If

Exit Sub

Errhandler: If Err = 2465 Then       ' If error is 2465 which is "Object-defined                          ' error." Resume Next              ' Resume running on next line after error. ElseIf Err = 2474 Then   ' If error is 2474 which is "No Control is                          ' active." Resume Next Else MsgBox Err & " " & Error  ' Show Error number and string of error ' value. Exit Sub End If

End Sub </li> Set the TimerInterval property of the Customers form to 200.</li> View the Customers form in Form view. Press TAB to move from one control to another. Note that the background color changes from white to yellow for each control that receives the focus.</li></ol>

NOTE: The TimerInterval property uses milliseconds (1000 = One second). Smaller numbers produce quicker responses. You may have to experiment with the numbers to achieve the effect that you want.

<div class="references_section">