472,101 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,101 software developers and data experts.

Change Link Child & Master Fields in VB

2
Hi!! I've been trying to figure this out..

I have a form with a subform and I need to display 2 different things in this subform, that's why I came with the idea of changing the Link Child Field and the Link Master Field.
This change should happen when clicking a button, so it would be helpful if somebody has an idea of how to change these fields in Visual Basic!!


The links between the forms actually work if I change the fields manually, but I want to use a button to do the same.

Name of the form: BaseForm
Name of subform: BaseSubform
Name of the table in use = Members
Name of the Field of the table I want to use = Assign

Expand|Select|Wrap|Line Numbers
  1.  ...
  2.  
  3. Private Sub ViewAllButton_Click()
  4.  
  5.     Forms!BaseForm.MasterRecordset = Members.Assign
  6.     Forms!BaseForm.ChildRecordset = Members.Assign
  7.  
  8. End Sub
  9.  
  10. ...

I appreciate your help!
Nov 6 '07 #1
4 31914
ADezii
8,830 Expert 8TB
Hi!! I've been trying to figure this out..

I have a form with a subform and I need to display 2 different things in this subform, that's why I came with the idea of changing the Link Child Field and the Link Master Field.
This change should happen when clicking a button, so it would be helpful if somebody has an idea of how to change these fields in Visual Basic!!


The links between the forms actually work if I change the fields manually, but I want to use a button to do the same.

Name of the form: BaseForm
Name of subform: BaseSubform
Name of the table in use = Members
Name of the Field of the table I want to use = Assign

Expand|Select|Wrap|Line Numbers
  1.  ...
  2.  
  3. Private Sub ViewAllButton_Click()
  4.  
  5.     Forms!BaseForm.MasterRecordset = Members.Assign
  6.     Forms!BaseForm.ChildRecordset = Members.Assign
  7.  
  8. End Sub
  9.  
  10. ...

I appreciate your help!
You can use the LinkChildFields and LinkMasterFields properties together to specify how Microsoft Access links records in a form to records in a subform. If these properties are set, Microsoft Access automatically updates the related record in the subform when you change to a new record in a main form.

Expand|Select|Wrap|Line Numbers
  1. 'Assuming [Assign] is the Linking Field Name in both Parent and Child
  2. Forms!BaseForm!BaseSubform.LinkMasterFields = "Assign"
  3. Forms!BaseForm!BaseSubform.LinkChildFields = "Assign"
Nov 6 '07 #2
MPat
2
You can use the LinkChildFields and LinkMasterFields properties together to specify how Microsoft Access links records in a form to records in a subform. If these properties are set, Microsoft Access automatically updates the related record in the subform when you change to a new record in a main form.

Expand|Select|Wrap|Line Numbers
  1. 'Assuming [Assign] is the Linking Field Name in both Parent and Child
  2. Forms!BaseForm!BaseSubform.LinkMasterFields = "Assign"
  3. Forms!BaseForm!BaseSubform.LinkChildFields = "Assign"
Thank you very much ADezii !!

it was really helpful and worked perfectly!
Nov 7 '07 #3
ADezii
8,830 Expert 8TB
Thank you very much ADezii !!

it was really helpful and worked perfectly!
Glad we can help you here at TheScripts.
Nov 7 '07 #4
sierra7
446 Expert 256MB
Hi

I have come across this thread because I am doing a similar sort of thing and was trying to resolve the error message, "You must use the same number of fields when you set the LinkChildFields and LinkMasterFields properties", even though both are being set the same.

I have a 'control panel' form with a sub-form window into which I am switching in and out six different 'detail' forms but some are linked by one field and others on two or three.

I have been changing the 'windows' (sub-forms) dynamically via command buttons in the control panel; running code to reassign the Master/Child links pretty much as described above.I don't always get the error; it depends upon what is being swapped and when. I had tried changing the object before the links, after the links; then Child bedfore Master etc. to no avail. In one instance the error even occurs when the two forms being swapped have the same three link fields!

I have finally found the fix is to first set the link fields to blank, then change the source object, finally reassign the links as appropriate, thus;-
Expand|Select|Wrap|Line Numbers
  1. 'de-assign link fields 
  2.   Me.DetailWindow.LinkChildFields = ""
  3.   Me.DetailWindow.LinkMasterFields = ""
  4.  
  5. 'replace sub-form with new source
  6.   Me.DetailWindow.SourceObject = "NewFormName"
  7.  
  8. 'reassign links as appropriate for NewFormName
  9.   Me.DetailWindow.LinkChildFields = "FieldName1, FieldName2, FieldName3"
  10.   Me.DetailWindow.LinkMasterFields = "FieldName1, FieldName2, FieldName3"
Which like all good puzzles if obvious when you know the solution! I hope someone finds this usefull
Dec 12 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Richard Cornford | last post: by
2 posts views Thread by Deborah V. Gardner | last post: by
2 posts views Thread by Chewy1026 via AccessMonster.com | last post: by
1 post views Thread by Hardik Shah | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.