Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

BackColor of ActiveControl

Posted on 2004-08-18
5
Medium Priority
?
334 Views
Last Modified: 2008-02-01
Hello, Experts! I'm using the following code in a module to 'highlight' the active field of a multi-tabbed form. In each field's GotFocus I have =Blue_BackGround(), in LostFocus I have =White_BackGround(). Works great, except opening the form produces "Run-time error '2474': The expression you entered requires the control to be in the active window." If I un-comment On Error..., seems to work ok but I'm wondering if that's the best way to deal with the problem. I've tried 'forcing' the ActiveControl to a field of the first tab, but can't seem to make that work. Thanks...Scott

Option Compare Database

Global Const PURE_WHITE = 16777215
Global Const PALE_BLUE = 16777175

Public Function White_Background()
    Screen.ActiveControl.BackColor = PURE_WHITE
End Function

Public Function Blue_BackGround()
    'On Error Resume Next
    Screen.ActiveControl.BackColor = PALE_BLUE
End Function
0
Comment
Question by:rsanglim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:rsanglim
ID: 11836663
One more thing...there's over 500 fields across 23 tabs, so simply putting a piece of code in the Got/Lost Focus would be a bit messy.
0
 
LVL 14

Expert Comment

by:ragoran
ID: 11837206
While a form is openning, and the Onfocus event of the first control is triggered, there is not yet an active control.

At the point you are right now, I will use the On Error resume next statement.

An alternative, if you have Access 2000 or more recent, will be to define conditional formating.  But for 500 fields, I am not certain of the impact on performance...

0
 
LVL 16

Accepted Solution

by:
ahmedbahgat earned 2000 total points
ID: 11838101
you can actually do thiseasy by making the the background color property of all controls the color you want to see when highlighted, then make the background  style property transparent, however when any control is focused the transparent background color should be visible,

no code is required


cheers
0
 

Author Comment

by:rsanglim
ID: 11841048
ahmedbahgat - I like your solution...clean and simple, no errors to deal with on form load. Thanks!
0
 
LVL 16

Expert Comment

by:ahmedbahgat
ID: 11841983
no problems, cheers
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question