472,129 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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

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 5704
Rabbit
12,516 Expert Mod 8TB
To reference an item on the parent form you can use either Me.Parent.ControlName or Forms!FormName!ControlName
Jul 26 '07 #2
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
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
12,516 Expert Mod 8TB
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
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
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 Expert Mod 8TB
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.

Similar topics

1 post views Thread by Kunal | last post: by
2 posts views Thread by William Wisnieski | last post: by
2 posts views Thread by Michelle | last post: by
reply views Thread by Access Programming only with macros, no code | 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.