Ms-access – Assign form field value to all records in subform

ms-accessms-access-2007

I'm pretty new to Access, so this may be very easy or obvious to some, or maybe it can't be done at all. I have searched this site, but I may not even be using the proper keywords. So far, I haven't found anything that helps me do what I am trying to do.

I have a form with a continuous subform in it. I have an unbound txt field on the main form called txtPO_num. In this form I run a query that displays all records that meet specified criteria in the continuous subform. I also have a control in the subform called PO_Num. My question is, how do I get the main form field value in txtPO_num to populate the PO_Num control in only the records displayed in the subform?

If there is another way to accomplish this I would be interested in knowing that too.

Best Answer

Execute an UPDATE statement which targets the same records which are included in the subform.

You have a SELECT query with a WHERE clause which identifies the records included in the subform's recordset. Build an UPDATE statement using the same WHERE clause. For example, if the SELECT were ...

SELECT field1, field2
FROM YourTable
WHERE field2 = 'foo';

... the UPDATE could be ...

UPDATE YourTable
SET field1 = 'new value'
WHERE field2 = 'foo';

Execute the UPDATE statement using the DAO database object's .Execute method.

Related Topic