Hello everybody,
I have a main form and sub form. How can I access the variables declared and set in main form in the sub form?
Thank you!
Hello everybody,
I have a main form and sub form. How can I access the variables declared and set in main form in the sub form?
Thank you!
You should be able to reference the variable using something like:
Code:Forms!FormName.VariableName
Thank you, for your reply!
Can you please provide me the exact syntax. I tried with the above syntax. It is not working. I m struggling to find out the correct syntax.
That pretty much is the exact syntax - you just need to supply the names.
FormName = The parent form where the variable was declaredCode:Forms!FormName.VariableName
VariableName = The name of the variable you declared on the parent form
The rest of it depends on what you are doing with the variable. Has it been given a value? Are you trying to use it in code or assign it to a field? etc... I can answer a lot more precisely if you upload a sample DB and tell me exactly what you hope to accomplish by accessing this variable.
Actually I am trying to do the exact same thing but it is giving error. Variable is declared and has value.
I tried to attach my database, but it seems site is not supporting '.accdb' files and I am not able to convert it to '.mdb' as it has features used by access 2007.
Brief about the code :
navigation is the Boolean var declared in the main(tblReflux) form, I am assigning it to 'True' when user presses the 'First' navigation button. Then, in the before update event of the sub form(tblReflux2 sub form) I am checking its value.
Here is the code:
Declaration and setting of var: ( Main form: tblReflux )
Accessing var in subform(tblReflux2 Subform):Code:Dim navigation As Boolean '<Global var> Private Sub cmdFirst_Click() navigation = True End Sub
I am getting error as 'Application defined or object defined error'(error no: 2465)Code:Private Sub Form_BeforeUpdate(Cancel As Integer) MsgBox "Subform beofore update" If Forms!tblReflux.navigation Then MsgBox "Navigation set" End If End Sub
Please let me know, if this explanation is not clear or if you want to know anything else.
I appreciate your time and help!
Thank you!
I think you need to change the way you declare your variable.
instead ofCode:Public navigation as BooleanIf you are still having problems I'm a lot better at figuring these out if I can see the DB. You can zip the ACCDB (should be some kind of an option when you right-click the DB file to Send To > Compressed (zipped) folder) and the system will let you upload it.Code:Dim navigation as Boolean
Yes! that was the problem.
Thank you!
Happy to help. Enjoy the rest of your weekend!