Passing variable to VBA event handler after execution
在执行方法/子程序后发生事件时,如何将变量传递给VBA中的事件?
详细信息:
1 2 3 4 5 6 7 8 9 10 11 | 'My Sub'''''''''''''''''''''''''' Private Sub mySub() structCalculateDateValues 'calculates a number of dates that I want to be unlocked on my form fnCreateTable 'create a table will all dates form my database End Sub 'Event handler for continous form''''''''''''''' Private Sub Form_Current() 'Some code to get the value of my Struct - structCalculateDateValues 'Lock records that do not fall within of the date parameters of the values in structCalculateDateValues End Sub |
这里的概念是我希望表单显示临时表中所有日期的记录,但只允许其中一些记录是可编辑的。这发生在MS Access 2013中。我的设置方法是:
这是效率问题,而不是其他任何问题,一个大问题是该事件是如何触发的。我还想避免一个导致我将struct成员值写入数据库的答案(这将是一个解决方案)。我认为VBA中必须有一种方法可以暂停执行以检测事件,对吗?
谢谢,
您需要一个模块级变量。这样,您可以从模块内的任何位置访问它:
1 2 3 4 5 6 7 8 9 10 | Option Explicit Private MyValue As MyValueType '<--- Private Sub Some_ParameterlessEventHandler() MyValue.SomeMember = 42 End Sub Private Sub SomeProcedureThatRunsAfterTheHandler() Debug.Print MyValue.SomeMember 'outputs 42 End Sub |