Reputation: 2306
How do I pass a variable to an event in VBA, when the event occurs after execution of my method/sub?
In Detail:
'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
The concept here is I want a form to show a record for all dates in a temp table, but only allow some of those records to be editable. This takes place in MS Access 2013. The way I have it set up is:
This is more a question of efficiency than anything else and a big question is how that event is triggered. I also want to avoid an answer that results in me writing my struct member values to the database (would be a cop-out). I think there has to be a way in VBA to pause execution to detect an event right?
Thanks,
Upvotes: 0
Views: 1224
Reputation: 71247
You need a module-level variable. That way you can access it from anywhere within the module:
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
Upvotes: 1