Access VBA Property Function - Subform Source Object Name? (1 Viewer)

misscrf

Registered User.
Local time
Today, 16:02
Joined
Nov 1, 2004
Messages
158
I received help on determining the active page of a tab control, by having the following code included in a form module:

Code:
Property Get ActivePage() As Access.Page
    'PROPERTY TO IDENTIFY WHICH TAB WE ARE ON, FOR FILTERING AND IDENTIFYING WHICH ACTIVE LISTBOX TO LOOK AT, FOR VALUES AND ACTIONS
    With Me.tbAddFind
        Set ActivePage = .Pages(.Value)
    End With
End Property

Now I want to do something similar, but instead of a tab control page, I'm looking to capture the name of the source object, for a subform control. I switch out the source object, and based on that, I need to change the header stuff - title caption, combo visible or not, combo rowsource, etc.

This is what I tried:

Code:
Property Get WhichSub() As Access.SubForm
    'PROPERTY TO IDENTIFY WHICH SUBFORM IS ACTIVE, FOR DETERMINING HEADER INFO AND BEHAVIOR
    With Me.SubEntryForm
        Set WhichSub = .SourceObject(.Name)
    End With
End Property

The .SourceObject is highlighted, when I attempt to compile, and I get an error that says "Wrong number of arguments or invalid property assignment".

Anyone know what I need to do, to get this to work? It will be helpful, in allowing me to write a simple select case, on that value, whenever I need in, during the operations on that form.

Thank you!
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 21:02
Joined
Jan 14, 2017
Messages
18,209
Code:
Property Get WhichSub() As Access.SubForm
    'PROPERTY TO IDENTIFY WHICH SUBFORM IS ACTIVE, FOR DETERMINING HEADER INFO AND BEHAVIOR
    With Me.SubEntryForm
        Set WhichSub = .SourceObject(.Name)
    End With
End Property

The problem is that SubEntryForm isn't valid ... at least not in Access 2010.
Unless of course you have defined it somewhere else

Also I'm not sure why you used bracketing in the Set line
AFAIK its not needed in either example
 

misscrf

Registered User.
Local time
Today, 16:02
Joined
Nov 1, 2004
Messages
158
subentryform is the name of the subform object. the control/frame that a form is set into, as the source object.

so Me.SubEntryForm.SourceObject = "x"
x is what I want to get out of this property procedure.
 

jleach

Registered User.
Local time
Today, 16:02
Joined
Jan 4, 2012
Messages
308
Why using parentheses after the SourceObject and ActivePage? Parentheses are used to access an element of a collection or array, which are not what you're working with.

Example
Code:
 = .SourceObject(.Name)
should be...
Code:
 = .SourceObject

SouceObject contains a string that is the name of the form, not a collection.
 

misscrf

Registered User.
Local time
Today, 16:02
Joined
Nov 1, 2004
Messages
158
.Pages(.Value) is how it works in the ActivePage property procedure. (.Name) is the attribute of the .SourceObject property that I am trying to access. The vba autocomplete even shows it in the list.
 

jleach

Registered User.
Local time
Today, 16:02
Joined
Jan 4, 2012
Messages
308
If we're talking about a subform control's SourceObject property, there is no "attribute" to the property... it's just a string:

https://msdn.microsoft.com/en-us/vba/access-vba/articles/subform-sourceobject-property-access

Therefore: = SomeSubControl.SourceObject

As mentioned, the () is for accessing the default collection of an object. SourceObject is not an object let alone a collection object or array. If you are trying to get the name of the form from the form object itself, the syntax would be:

MySubControl.Form.Name
 

misscrf

Registered User.
Local time
Today, 16:02
Joined
Nov 1, 2004
Messages
158
Thanks for all your replies. I kept playing with it, and found I could simplify this a lot.

Just tested this, and it seems to work:

Code:
Property Get WhichSub() As String
    'PROPERTY TO IDENTIFY WHICH TAB WE ARE ON, FOR FILTERING AND IDENTIFYING WHICH ACTIVE LISTBOX TO LOOK AT, FOR VALUES AND ACTIONS
    WhichSub = Me.SubEntryForm.SourceObject
End Property

Thank you!
 

Users who are viewing this thread

Top Bottom