I trying to pass a value from one form to another, store it in a variable and be able to use the variable in all of the Sub of the form.
I am calling my form using
Code:
DoCmd.OpenForm "ViewCompany", , , , , , Me!CompanyCombo.Value()
In Form_ViewCompany, I am retrieving this value in Private Sub Form_Load():
Code:
CompanyID = CInt(Me.OpenArgs)
Now this works if I declare CompanyID as a global variable in a module
Code:
Public CompanyID As Integer
I want to avoid using global variables as it might create problems and conflicts later in my form workflow.
If I declare CompanyID in Private Sub Form_Load(), I cannot use this value in other Private Sub associated with the form, for example, with an On_Click() event.
I would like to know how to declare a variable (and set its value) that can be used in all Sub associated with a form, but cannot be accessed from other forms. I believe this is a "scope" problem and I am trying to figure out the best way to do it. Some people online are suggesting storing the passed value in a hidden Text Box on the form and use its .Value in the other Sub, but I am sure there must be a better way to do this.
Thanks