Global variable

peljo

Registered User.
Local time
Today, 11:02
Joined
May 24, 2006
Messages
24
In my form i have to declare seceral times the following expression:

Dim OfficeBranch As Control
Set OfficeBranch = Me.Controls("Branch" & (Me.Parent.office - 1))

Can i make the above expression to be valid for all the functions in the form, and thus avoid declaring it in each case?
 
You'll have to get rid of the "Me" and "Parent" keywords because those are form specific and you declare globals outside of the scope. In other words, Me and Parent have no context where you declare it (the top of a non-form-based module).
 
What I do if I need a calculated form global variable like this is create a private property on the form...
Code:
private m_branch as access.control

private property Get OfficeBranch as access.control
  if m_branch is nothing then 
    set m_branch = Me.Controls("Branch" & (Me.Parent.office - 1))
  end if
  set OfficBranch = m_branch
end property
If the variable Is Nothing, as it will be on first reference, it is created. It's available to all procedures on your form, and you can even bind the value, in some cases, to a textbox on your form.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom