Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

Access Controls

Hi. I have an Access 2010 Form, on which there are plenty of controls (textboxes), let's say that their names are TB1, TB2, TB3, ..., TB50. Is there a way to know which one was clicked ?

I want to change the textbox backcolor to different one, but I don't want to place 50 functions of TB*_click event. Hope I'm clear. Please ask if not.
0
Lukasz Chmielewski
Asked:
Lukasz Chmielewski
  • 2
1 Solution
 
Dale FyeCommented:
I would recommend conditional formatting.  Select all of the textboxes at once, then click conditional formatting on the ribbon.  

In the dropdown associated with Condition1, select "Field has Focus", then set the background color you want the control to have when it gets the focus.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Create a Function in a regular VBA module. Let's say:

Public Function mWhichControl()
    Debug.Print Screen.ActiveControl.Name    '
 'real code here

End Function

Screen.ActiveControl.Name will give you the Name property of the control
Screen.ActiveControl   by itself will give the the Value of the control


Now, Select ALL your Controls at once, the put this on the Click (Or whatever event you choose) Event - directly on the Property Sheet:

=mWhichControl()

This will call the common function ...

mx
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
1
0
 
Lukasz ChmielewskiAuthor Commented:
That's it, thanks a lot !
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now