473,811 Members | 2,767 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 32973
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
2644
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
21057
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
8483
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
3768
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
3523
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
8301
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
6674
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
8643
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
3040
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
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10398
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,...
0
10133
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7669
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
6889
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
5554
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...
1
4339
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
3
3017
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.