Is it possible to have a variable declared and set in a parent form, and then referenced by a subform without making the variable public? For example, can you directly reference that variable from the subform in a similar way that you reference a field on the parent form? Thanks in advance.
What is wrong with making the variable public in the MainForm? When you do it then becomes a property of the MainForm and can be referenced the same way you would reference any property of the MainForm.
Public variable is accessible to *all* forms, code modules and any objects that may use it.
Private variable is accessible to all routines within a module that has the private variable declared. Private variable are not visible to another modules.
Local variable (the ones we normally use) are of course confined to a single routine.
However, if I'm remembering this correctly, there's also Static variable, which is essentially a local variable but doesn't get destroyed between calls. However, Static will keep the value until explicitly changed, and I've yet to find a good use for it.
A sample code:
Code:
Option Compare Database
Option Explicit
Private IntX As Integer
Public StrSQL As String
Static IntPatientID As Integer
... subroutines executed below...
Alternatively, you could just pass argument using a Call (). Make a custom routine in your subform that will accept arguments. Example:
Code:
Public Sub MySubRoutine (IntX As Integer, StrBlah as String)
... code executes here...
End Sub
then in the form you can call it
(This is off the top of my head, and may have syntax error)