If you want set a reference to a control field of the subform from a form the way is this:
its the same.
But if you want to set a reference to control subform in a form the way is:
Originally posted by TheGame7
I don't think you understand me fully.
It is something in the code, since if I access it as a sub form from the main form it WORKS!
If I access the form alone, i.e. double clicking it from the list of forms, I get a parameter query (error)
How can I get it to work both ways?
A form can be in one of 2 states - as a stand alone form or as a sub-form. The reason you get an error message when you open the sub form as a form is that it is looking for a parent form that you have referenced in SQL or VBA. No parent form is available so you get an error. You need a function to test to see how the form has been opened:
Public Function IsSubForm(frm As Access.Form) As Boolean
' Check the parent property to see if one exists
Dim strName As String
On Error Resume Next
strName = frm.Parent.Name
IsSubForm = (Err.Number = 0)
to use the function in your form you use code such as:
If IsSubForm(Me) Then
' It's a sub form - change SQL or anything else as required
' It's a stand alone form