Get subform and control name that has focus?

Or something more advanced. All of this has to go at the beginning.
Constants, Enums, Class variables, Events
Code:
Option Compare Database
Option Explicit


'References: Microsoft Windows Common Controls
'If this in not in the list, browse for MSCOMCTL.OCX in the reference browser
'Normally located in C:\Windows\System32
'If you cannot find it download from microsoft
'MS scripting runtime if planning to save the sort order
'Microsoft Office 14 (or later) for command bars

Const ID_Field = "ID"
Const Parent_ID_Field = "ParentID"
Const Node_Text_Field = "NodeText"
Const Identifier_Field = "Identifier"
Const Image_Name_Field = "NodeImage"


Private WithEvents mTVW As TreeView
Private mQueryName As String
Private mRootParentID As String
Private mRecordSet As DAO.Recordset
Private mLoadType As lt_LoadType
Private mAllowDragDrop As Boolean
Private mTree As TreeView
Private mLoadImages As Boolean

'Consider if you want a PK and not the node
Public Event TreeviewNodeClick(SelectedNode As Node)
Public Event TreeviewNodeCheck(CheckedNode As Node, Checked As Boolean)
Public Event TreeviewNodeDragDrop(DragPK As Variant, DropPK As Variant, DragNode As Node, DropNode As Node)
Public Event TreeviewNodeDblClick(SelectedNode As Node)
Public Event RightClickOnNode(SelectedNode As Node)
Public Event RightClickOffNode()
Public Event NodeIterated(Node As Node)
Public Event ExpandedBranch(ExpandedNode As Node)

Public Enum lt_LoadType
  lt_lightload = 1
  lt_fullload = 2
End Enum
 
Great advice. Works like a champ! Thanks a bunch.
Now to my other issue.
 
The down fall of this approach is you take away an event that you may have wanted to use for something else. You put the function in all the controls onfocus.

If you are interested in a more robust way to do this that does not take up an event that may be used, you could use the concept of
Event Sink, Event Bridge, Notifier class (choose your name)

See this discussion, we all described the same idea using different names.

The idea is the same. You can have a single class with a method that raises an event when the method is called. Many other objects can listen for that event. This way you can have many objects call the method to raise an event. Every object then only has to know about the event bridge (sink, notifier) and not maintain a reference to all the other objects.

In this way you could theoretically very easily add every control in the database reference the event bridge. Every form very easily could know what control has focus..
 
Right now my Conditional Formatting expressions are all hard-coded. While it works, I’d like to make my forms universal to make it easier to apply to other applications.

For dynamic conditional formatting see the whole discussion and demo


It shows how to do dynamic formatting by adding conditions at runtime, and goes into a common issues that people run into.
 
Thanks for the references. I'll dive into them and begin learning again.
 
If you want this code to support your conditional formatting, I say it is not needed. See my proposed solution. As long as you are exact in your names where the two Controls have the same name just different prefixes it will work easily.
 

Users who are viewing this thread

Back
Top Bottom