By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,060 Members | 1,893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,060 IT Pros & Developers. It's quick & easy.

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

P: 5
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
Share this Question
Share on Google+
7 Replies


Rabbit
Expert Mod 10K+
P: 12,357
To reference an item on the parent form you can use either Me.Parent.ControlName or Forms!FormName!ControlName
Jul 26 '07 #2

P: 5
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

P: 5
To reference an item on the parent form you can use either Me.Parent.ControlName 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!Field1

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
Expert Mod 10K+
P: 12,357
You can't do Forms!SubformName!ControlName

You can do Forms!ParentName!SubformName.Form.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

P: 5
You can't do Forms!SubformName!ControlName

You can do Forms!ParentName!SubformName.Form.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

P: 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?
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
Expert Mod 10K+
P: 12,357
Not a problem, good luck.
Jul 26 '07 #8

Post your reply

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