I have multiple events (click, afterupdate, etc) that perform different actions using the same object. How do I assign an object's reference only once so that I don't have to retype it for every sub or function. For example, the below code works, but I'm trying to avoid typing the "Set userName = me.userName" for every event. Isn't there a way to define it and use it for all subs? Here is a general script the shows what I mean.
Code:
Public Sub button1_Click Dim userName, field1 Set userName = me.userName Set field1 = me.field1 MsgBox "Button 1 was clicked" End Sub Public Sub button2_Click Dim userName, amount1 Set userName = me.userName Set amount1 = me.amount1 MsgBox "Hi " & userName & ". The amount is:" & amount1 End Sub
Comment