Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 12-11-2017, 06:06 AM   #1
y_wally
Newly Registered User
 
Join Date: Dec 2017
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
y_wally is on a distinguished road
Get value of Link Master Field

Hi,

I've got a main form with 2 times the same subform on it.
Only the Link Master Fields is different for these subforms.
I have an add button on this subform, but I need the ID that is given in the Link Master Field to store my data.
How can I achieve this?

y_wally is offline   Reply With Quote
Old 12-11-2017, 06:35 AM   #2
arnelgp
Registered User
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 7,601
Thanks: 59
Thanked 2,436 Times in 2,336 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Get value of Link Master Field

it is automatically saved when you have link.
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 12-11-2017, 12:08 PM   #3
Cronk
Newly Registered User
 
Join Date: Jul 2013
Posts: 2,125
Thanks: 3
Thanked 462 Times in 455 Posts
Cronk will become famous soon enough Cronk will become famous soon enough
Re: Get value of Link Master Field

The link fields are properties of the sub form object ie
me.sfYourSubform.linkChildFields
me.sfYourSubform.linkMasterFields

where sfYourSubform is the object name of the sub form in the parent form

Cronk is offline   Reply With Quote
Old 12-12-2017, 12:19 AM   #4
y_wally
Newly Registered User
 
Join Date: Dec 2017
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
y_wally is on a distinguished road
Re: Get value of Link Master Field

@Cronk, this code works when you are on the mainform.
But when I'm on the subform, how can I know these values?

Or how can I get the name of my subform like it's named on the mainform?
y_wally is offline   Reply With Quote
Old 12-12-2017, 12:42 AM   #5
arnelgp
Registered User
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 7,601
Thanks: 59
Thanked 2,436 Times in 2,336 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Get value of Link Master Field

to get the LinkMasterFields (the control name) from subform:

Forms(Me.Parent.Name)(Me.Name).LinkMasterFields

to get the LinkMasterFields' Value:

Me.Parent.Controls(Forms(Me.Parent.Name)(Me.Name). LinkMasterFields).Value
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 12-12-2017, 12:46 AM   #6
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 9,825
Thanks: 107
Thanked 2,660 Times in 2,434 Posts
isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all
Re: Get value of Link Master Field

For more info on referencing subform controls, see these links

http://allenbrowne.com/casu-04.html

http://access.mvps.org/access/forms/frm0031.htm
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
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.
,
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.


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.
isladogs is offline   Reply With Quote
Old 12-12-2017, 04:12 AM   #7
y_wally
Newly Registered User
 
Join Date: Dec 2017
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
y_wally is on a distinguished road
Re: Get value of Link Master Field

@arnelgp, something like your code I'm looking for.
But the problem is that the I have changed the name of the subform on the mainform. Because I have this subform twice on the mainform.
Therefore I need to know what is the name of the subform.
Because with your mentioned code, me.name gives the name of the subform as I have created it, but not the name as I have named it on the mainform.
Thanks for your help.

y_wally is offline   Reply With Quote
Old 12-12-2017, 04:46 AM   #8
arnelgp
Registered User
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 7,601
Thanks: 59
Thanked 2,436 Times in 2,336 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Get value of Link Master Field

you should'nt do that.
it is referencing the same Subform, whether you rename it.
you should instead create a copy (copy paste) the subform in Navigation Pane.
rename the copy and used that copy as your main form.
therefore you willl have unique names of subform.
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 12-12-2017, 04:59 AM   #9
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,164
Thanks: 495
Thanked 904 Times in 856 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Get value of Link Master Field

Quote:
Originally Posted by y_wally View Post
I have changed the name of the subform on the mainform.

I don't think so. I think it's more likely you have changed the name of the subform/subreport control (which I referred to as a subform window) this is a hidden control which actually houses the form you refer to as a subform.

Here is the first video of a playlist I intend to create on subforms. Might provide you with a bit more information on how they work...

Sub-Forms
__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
Old 12-12-2017, 05:11 AM   #10
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,164
Thanks: 495
Thanked 904 Times in 856 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Get value of Link Master Field

Quote:
Originally Posted by arnelgp View Post
create a copy (copy paste) the subform in Navigation Pane.
I'm not sure that is the solution because I don't think you have to worry about the name of the subform. You can find the subform by referring to it as the form enclosed in a particular subform/subreport control.

Regarding multiple copies of the same form, I do understand this method of building databases, that is creating duplicates of the same form with minor alterations to serve a slightly different functions. And it is probably an acceptable process when you are designing, however you should endeavour to use the same form many times. Instead of creating multiple duplicates with slightly different functionality, what you do is add the different functionality with VBA code. This is demonstrated in the video on Subforms. The video Here:- Sub-Forms shows a main form that appears to have 4 subforms on it, however it only has one subform modified with VBA code to perform four slightly different functions. The demonstration is of a Time Management Matrix.
__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
Old 12-12-2017, 05:23 AM   #11
y_wally
Newly Registered User
 
Join Date: Dec 2017
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
y_wally is on a distinguished road
Re: Get value of Link Master Field

Quote:
Originally Posted by arnelgp View Post
you should'nt do that.
it is referencing the same Subform, whether you rename it.
you should instead create a copy (copy paste) the subform in Navigation Pane.
rename the copy and used that copy as your main form.
therefore you willl have unique names of subform.
But when I change something on the subform, I have to change it in every copy. Otherwise I only have to change it once.
y_wally is offline   Reply With Quote
Old 12-12-2017, 05:26 AM   #12
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,164
Thanks: 495
Thanked 904 Times in 856 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Get value of Link Master Field

Quote:
Originally Posted by y_wally View Post
But when I change something on the subform, I have to change it in every copy. Otherwise I only have to change it once.
I couldn't have said it better myself! Oh! I think I did!
__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
Old 07-14-2019, 02:01 PM   #13
SomeSmurf
Newly Registered User
 
Join Date: Jul 2019
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
SomeSmurf is on a distinguished road
Re: Get value of Link Master Field

Hello everyone!
Bit old thread but not sure the question was fully answered. And what if the question is same as original post, but the form is used with multiple instances of the main form too? Is using the forms collection still best option in that case or is there some other way?

Seems weird that there is no (accessible read only) run time property in form that contains the value of the master link field so it can easily be accessed in any subform.

/SomeSmurf
SomeSmurf is offline   Reply With Quote
Old 07-14-2019, 02:09 PM   #14
SomeSmurf
Newly Registered User
 
Join Date: Jul 2019
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
SomeSmurf is on a distinguished road
Re: Get value of Link Master Field

Me.Parent.Form.CurrentRecord

so maybe not that tricky
SomeSmurf is offline   Reply With Quote
Old 07-14-2019, 02:11 PM   #15
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,164
Thanks: 495
Thanked 904 Times in 856 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Get value of Link Master Field

Quote:
Originally Posted by SomeSmurf View Post
but the form is used with multiple instances of the main form too?
I don't understand?

Sent from my Pixel 3a using Tapatalk

__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to link master field to textbox on main form evoingram Modules & VBA 1 11-21-2016 04:50 PM
Revising Data In Link child & Link Master Field duffy Forms 2 04-19-2009 05:35 PM
Link master field, on another subreport Gkirkup Reports 1 04-03-2009 01:15 AM
Setting Link Master Field in VB mnbuckland Modules & VBA 2 12-08-2008 10:00 PM
Making the Subform Master Field Link a Control ^Nightwing^ Forms 0 09-21-2004 02:46 AM




All times are GMT -8. The time now is 05:11 AM.


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

Featured Forum post


Sponsored Links


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