473,837 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use a button to update a field in parent form based on record selected in subform?

5 New Member
I have a simple form with 4 fields, and a subform that retrieves records that are potential matches based on a query.

The user will use the ID from the subform record and enter it into one of the fields on the main form (this is how the match will be stored).

Is there a way using a button/macro to populate the parent form's field with the ID of the subform record that is currently selected?

For example, the subform loads 7 records. The user highlights record 3, which shows 3 fields, one of them the PK. The user would then click this button, and one of the fields in the table the parent form is based on would be updated with the PK of the record selected in the subform.

Right now, they are manually copying & pasting, but it seems like I should be able to write a macro to do this.

Thoughts?

Thanks!
Jul 26 '07 #1
7 6219
Rabbit
12,516 Recognized Expert Moderator MVP
To reference an item on the parent form you can use either Me.Parent.Contr olName or Forms!FormName! ControlName
Jul 26 '07 #2
dscarbor
5 New Member
So if I want to pull the PK of the selected record on the subform, what would that be?

Forms!Form1!???
Jul 26 '07 #3
dscarbor
5 New Member
To reference an item on the parent form you can use either Me.Parent.Contr olName or Forms!FormName! ControlName
Sorry, to be more explicit:

If I want Field1 of the SELECTED record in the subform, and to update the active record in the parent form...

Is the selected record something like:
Forms!Subform!F ield1

Or is there some tag like ".selected" that I need in there?

I think once I have that, it's a matter of a simple update query that uses that item.

Thanks!
Jul 26 '07 #4
Rabbit
12,516 Recognized Expert Moderator MVP
You can't do Forms!SubformNa me!ControlName

You can do Forms!ParentNam e!SubformName.F orm.ControlName
However, if you're going to be in the subform anyways, it'd be easier to use Me.ControlName

So basically, if you want to set a field, MatchedKeyField , on the parent form using the PK field, PrimKeyField, of the subform, then in your code you would type:
Expand|Select|Wrap|Line Numbers
  1. Me.Parent.MatchedKeyField = Me.PrimKeyField
  2. OR
  3. Forms!FormName!MatchedKeyField = Forms!FormName!SubformName.Form.PrimKeyField
  4. OR any combination of the two.
  5.  
Jul 26 '07 #5
dscarbor
5 New Member
You can't do Forms!SubformNa me!ControlName

You can do Forms!ParentNam e!SubformName.F orm.ControlName
However, if you're going to be in the subform anyways, it'd be easier to use Me.ControlName

So basically, if you want to set a field, MatchedKeyField , on the parent form using the PK field, PrimKeyField, of the subform, then in your code you would type:
Expand|Select|Wrap|Line Numbers
  1. Me.Parent.MatchedKeyField = Me.PrimKeyField
  2. OR
  3. Forms!FormName!MatchedKeyField = Forms!FormName!SubformName.Form.PrimKeyField
  4. OR any combination of the two.
  5.  
Thanks for the quick reply. I've got to be getting close, but I'm getting an error.

The name of the main form is "AssignIds" . The field in that form to be updated is "NewID". The name of the subform is "Pass2 subform" and the Field to pull from (primary key) is "Field1". I wrote the below, but it is erroring out:

Forms!AssignIds !NewID = Forms!AssignIds ![Pass2 subform].Form.Field1

Thoughts?
Jul 26 '07 #6
dscarbor
5 New Member
Thanks for the quick reply. I've got to be getting close, but I'm getting an error.

The name of the main form is "AssignIds" . The field in that form to be updated is "NewID". The name of the subform is "Pass2 subform" and the Field to pull from (primary key) is "Field1". I wrote the below, but it is erroring out:

Forms!AssignIds !NewID = Forms!AssignIds ![Pass2 subform].Form.Field1

Thoughts?
Nevermind!!! I'm an idiot...the field name wasn't Field1...I had aliased it in the query. Sorry and thanks for all your help!!!
Jul 26 '07 #7
Rabbit
12,516 Recognized Expert Moderator MVP
Not a problem, good luck.
Jul 26 '07 #8

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

Similar topics

1
5187
by: Kunal | last post by:
Hi, I need some help on writing an update query to update "UnitsSold" field in Products Table whenever I save a transaction. The transaction may contain several "Subtransactions", one for each product sold in that transaction. I have a subtransaction table that maintains record of each subtransaction, with data such as: ProductID, Quantity, TransactionID etc. The Products table has fields: ProductID, UnitsSold, UnitsOrdered,...
2
4792
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text box that references a field on the subform. What I'd like it to do is show the value in the field of the last record entered on the subform. But what its doing is referencing whatever record the user clicked on last before closing all the forms. Also if the user cleared the subform field, I would like the text box on the main...
3
1963
by: Earthling | last post by:
Any help would be appreciated to solve the following simple problem that I will describe. *** There is a form called "red chocolate form". The form has a particular subform field that has a checkmark box that is selectable as on or off (on if there is a checkmark inside it). The table that contains the data for the form is known as "red chocolate
2
5795
by: Michelle | last post by:
Hi all I have used knowledge base article 112747 to improve my subforms performance. I am using Access 97. I have a main form where i put an extra textbox which concatenated TeamID WeekNum Weekday, ie value might be 15Monday. I then put in a field in my query behind my subform which held the same info and used these fields to link the mainform to the subform.
25
10283
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the data in each record, which includes the ID of the father and the mother (who also have records in the table). One record per form. I have a Tab Control in the form, and in one of the tabs I have a subform (sfmSiblings) in which I wish to list...
1
6480
by: Jim | last post by:
I have a form which is based on a join query. The join relationship is one to many. When a new record is added and the user enters a value for one of the fields in the "many" records, I attempt to lookup (using DLOOKUP) the parent record and set the join field in the subordinate record to the key for the parent record. However, when I do this I receive the error "3341 - The current field must match the join key <field> in the table that...
2
5235
by: emc_cos | last post by:
I have a very nice parent child relationship happening between a main form and 8 subforms. The main form is the data entry point for a table that holds textual data like names, notes and the like. It also holds the primary key which is an alpha-numeric file designation. The subforms are the data entry point for another table that holds numeric values for time spent on tasks.
13
3287
by: bitsnbytes64 | last post by:
Hi, I have a form which contains a subform. Both are were creetd using the form wizard and are bound by the column IXO_NR (on two different tables), which is the control source for a textbox on both the parent and subform. The intent was to default the subform's IXO_NR to the parent form's IXO_NR, then requery the subform to prevent the user from having to scroll through all of the subform's records to find the one they may be looking for....
0
3243
by: Access Programming only with macros, no code | last post by:
ERROR MESSAGE: Could not update; currently locked by another session on this machine. BACKGROUND I have the following objects: Table1 - HO (which has about 51,000+ records) Table2 - Contact (which has 68,000+ records)
0
9830
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...
0
9682
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10562
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10615
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
9390
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
7803
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
6989
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();...
2
4036
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3122
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.