ACC2000: How to Change Active Control Background Color with Timer Event
ID: Q210187
|
The information in this article applies to:
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, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals 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 needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the
following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp
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
- Set the TimerInterval property of the Customers form to 200.
- 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.
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.
REFERENCES
For more information about the background colors, click Microsoft Access Help on the
Help menu, type "Change the background color of a control or section" in the Office Assistant or the Answer Wizard,
and then click Search to view the topic.
Additional query words:
inf
Keywords : kbusage kbdta AccCon PgmObj KbVBA
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto