Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change variable from subform in the code from a form

Status
Not open for further replies.

fedum

Technical User
Mar 22, 2004
104
BE
is it possible to change the value of a variable in the code of a subform using the code from the form? Or is this only possible with a global variable?
Thanks!
 
Yes it is possible. A form variable is a class variable so you have to fully reference the class object.
Me.subformControlName.form.someVariable = ..

Can you explain? There may be some better structure.
 
Sorry, but I still get a error. I just:
Me.frmKassa_Subformulier.Form.teller = 0

Error created by the object or the aplication

 
That is a really strange error, might be something else going on. However, the variable in the subform needs to be a public variable defined at the top of the subforms module.


Can you explain what you are trying to do? There may be some better structure.
 
I would recommend structuring this like a standard class module. So treat the variable like a property

Assume my variable is called "mMyName" and the form is "form1". I want to be able to set the value and get the value from another form. I make a get and let property
Code:
Private mMyName As String

Public Property Get myName() As String
  myName = mMyName
End Property

Public Property Let myName(theName As String)
  mMyName = theName
End Property

then externally if I want to set the value

forms("form1").myName = "someName"
if I want to get the value
msgbox forms("form1").myName
 
Thanks! I found the reason. I used Private as declaration instead of Public.
Thanks, your explanation was very useful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top