473,721 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change Link Child & Master Fields in VB

2 New Member
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 32931
ADezii
8,834 Recognized Expert Expert
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 LinkMasterField s 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 New Member
You can use the LinkChildFields and LinkMasterField s 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,834 Recognized Expert Expert
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 Recognized Expert Contributor
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 LinkMasterField s 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

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

Similar topics

4
2633
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an QA tested for a new year release. I don't think that going to prove practical, but there is no harm in trying :) and some serious family commitments. But it has to be done soon so this is stage one. Mike Winter provided an extensive list of...
2
21055
by: Deborah V. Gardner | last post by:
I am using Access 97 and have had a problem joining a main form and a subform. I have a main form and a subform. The data source on the main form is a SELECT statement referring to three tables. The subform's data source is a table. When I try to link the Child and Master fields, I get the message "Can't build a link between unbound forms." I have tried typing in the common fields and it still does not work.
3
8479
by: Mark C | last post by:
I have a unbound form with a tab control with four tabs in an Access 97 database. On each tab I have a sub form each form on the sub forms is bound to its own table. Each table has a field that can link them all together. I have put an invisible unbound control on the master form that gets populated on open. I set the link child and link master of each sub form to the unbound control on the master form. When the form opens all the subforms...
2
3765
by: Chewy1026 via AccessMonster.com | last post by:
Is this even possible. To be able to have a subform where the Master field on the main form is linked to the subform via 1 child field OR another? So the table for the main form, can be matched to 2 different fields (one or the other). Can this be done with only 1 subform? -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/databases-ms-access/200510/1
1
3518
by: Hardik Shah | last post by:
Hi, I have created a form for sales bill information. I am using two tables, its salient filds are as below. 1) Bill - Fields - bill_id,customer_id,tdate 2) Itemtran - Fields - itemtran_id,bill_id,item_id,price I am using datagrid for Itemtran table. in case of new bill creation , I can't know new bill_id before updating data. As my itemtran table's field bill_id doesn't accept null value, I have to replace bill_id . Temporary, I
13
8294
by: paquer | last post by:
Ok' I have 2 tables. The first being my main table where each record has a 'FigureID' txt box. (Indexed - No duplicates) The second being my sub table where reporting is entered for these Figures. Sometimes more than one at a time. I have 4 'FigureID' txt boxes on this subtable.(All Indexed - Duplicates OK) When I set the Master/Child link for the first FigureID on the Subtable I have no problems.
11
6659
imrosie
by: imrosie | last post by:
Hello Experts This is a hard one (I still speak newbie). An expert may think it's not a big deal, but, I am trying to replace my Main Order form with a subform because of the following: Original form was based on a query of 2 tables (Order and Customers), the subform was based on table OrderDetail(productname, quantity, discount, unitprice). I was experiencing autonumber problems when attempting to start a new order, because of the inner...
1
8636
by: Yubin | last post by:
Hello, I'm new to the forums and I wasn't able to find anything in my searches so here we are. I have a DB with a many-2-many relationship. I have a form that has 3 comboboxes: Project #, Last Name, Active(Yes/No) I have a subform that uses Project# as a Child and Master link. I want to use all three exclusively to give the user the option to search using any ONE of the three, but when I add all three to the Child and Master link fields no...
12
3028
by: banderson | last post by:
Hello all, I am hoping that you can help me with a problem that has occurred numerous times on various forms in the two databases that I am working on. When I first add a subform to a form linking child and master fields (primary key and foreign key), the subform will automatically update when the master field on the main form is changed (it is in a combo box). However, when I work more on the form - making it a bit more complicated, adding...
0
9366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9130
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6668
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4751
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3188
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2574
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.