Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 12-07-2017, 07:40 AM   #1
misscrf
Newly Registered User
 
Join Date: Nov 2004
Location: earth
Posts: 144
Thanks: 5
Thanked 3 Times in 3 Posts
misscrf is on a distinguished road
Red face Access VBA Property Function - Subform Source Object Name?

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!

__________________
misscrf

It is never too late to become what you could have been ~ George Eliot



To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by misscrf; 12-07-2017 at 07:41 AM. Reason: posted same code twice.
misscrf is offline   Reply With Quote
Old 12-07-2017, 07:52 AM   #2
ridders
AWF VIP
Gold Supporter
 
ridders's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 2,918
Thanks: 52
Thanked 686 Times in 634 Posts
ridders has a spectacular aura about ridders has a spectacular aura about
Re: Access VBA Property Function - Subform Source Object Name?

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
__________________
Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
, Tapatalk


If this answer has helped, please click the Thanks button and/or click the 'reputation' scales symbol on the left and leave a comment. Cheers!
ridders is offline   Reply With Quote
Old 12-07-2017, 07:54 AM   #3
misscrf
Newly Registered User
 
Join Date: Nov 2004
Location: earth
Posts: 144
Thanks: 5
Thanked 3 Times in 3 Posts
misscrf is on a distinguished road
Re: Access VBA Property Function - Subform Source Object Name?

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.

__________________
misscrf

It is never too late to become what you could have been ~ George Eliot



To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
misscrf is offline   Reply With Quote
Old 12-07-2017, 07:58 AM   #4
jleach
Newly Registered User
 
Join Date: Jan 2012
Location: New York, NY
Posts: 134
Thanks: 6
Thanked 26 Times in 26 Posts
jleach will become famous soon enough
Re: Access VBA Property Function - Subform Source Object Name?

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.
__________________
- Jack D. Leach - Dymeng Services
jleach is offline   Reply With Quote
Old 12-07-2017, 08:01 AM   #5
misscrf
Newly Registered User
 
Join Date: Nov 2004
Location: earth
Posts: 144
Thanks: 5
Thanked 3 Times in 3 Posts
misscrf is on a distinguished road
Re: Access VBA Property Function - Subform Source Object Name?

.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.
__________________
misscrf

It is never too late to become what you could have been ~ George Eliot



To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
misscrf is offline   Reply With Quote
Old 12-07-2017, 08:05 AM   #6
jleach
Newly Registered User
 
Join Date: Jan 2012
Location: New York, NY
Posts: 134
Thanks: 6
Thanked 26 Times in 26 Posts
jleach will become famous soon enough
Re: Access VBA Property Function - Subform Source Object Name?

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...roperty-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
__________________
- Jack D. Leach - Dymeng Services
jleach is offline   Reply With Quote
Old 12-07-2017, 08:05 AM   #7
misscrf
Newly Registered User
 
Join Date: Nov 2004
Location: earth
Posts: 144
Thanks: 5
Thanked 3 Times in 3 Posts
misscrf is on a distinguished road
Talking Re: Access VBA Property Function - Subform Source Object Name?

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!


__________________
misscrf

It is never too late to become what you could have been ~ George Eliot



To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
misscrf is offline   Reply With Quote
Reply

Tags
access 2010 , property , sourceobject , vba access 2010

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename source object in subform shafara7 Forms 2 06-06-2017 04:40 AM
Problems referencing control on subform after changing source object of subform JFHBIFF Modules & VBA 3 02-28-2009 09:25 PM
setting subform source object matthew8614 Forms 6 08-18-2008 08:58 AM
Query as subform's source object voiD Forms 2 09-11-2005 06:25 AM
Alter Source Object of Subform jwindon Forms 4 02-01-2002 02:15 PM




All times are GMT -8. The time now is 11:22 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World