So I’m doing some proof of concept here.
I want to use a starting syntax like the following in the Debug.Print line:
Public Sub TestCustomTags()
Dim testCT As CustomTags
Set testCT = New CustomTags
Dim ctl As Access.Control
Set ctl = Form_TestForm.TestControl
Debug.Print testCT(ctl)
' Eventually code should do something like
' testCT(ctl)("OriginalLeft")
' and that should be able to print a string that I had set.
End Sub
'Class module CustomTags
Option Compare Database
Option Explicit
'@DefaultMember
Public Function Controls(ctl As Access.Control) As String
Controls = ctl.Name
End Function
Now the trick here to get the testCT(ctl) syntax is to set a default member in the class.
This basically makes testCT.Controls(ctl) and testCT(ctl) mean the same thing to VBA.
This is not a feature available for manipulation within the VBE environment.
You either have to export your file to text, add a line and reimport the class, or if you are a RubberDuckVBA user you can use the code I have above using ‘@DefaultMember before the Function/Sub/Property that I want to be default and then that opens up the syntax I’m using.
In order to do this with RubberDuck see the comments at the end of this article: https://rubberduckvba.blog/2019/12/14/rubberduck-annotations/#comment-4376
In order to do this using the export / import method, check out this article: http://www.cpearson.com/Excel/DefaultMember.aspx
Now I’ll be able to use another class with another default member to fully implement this. I’m looking forward to a final quick implementation of the basic functionality on Monday.