pTrying to poulate two field on a modal form from field values on a main form and a sub-form

I'm trying to populate two field on a modal form from field values on a main form and a sub-form.

Here is my code but the two lines aren't populating the modal form:

    DoCmd.OpenForm "frmPartsAdditionForm", , , , acAdd, acDialog, NewData
    Forms!frmPartsAdditionForm.txtVendor = Forms!frmReceivingFormHeader!cboVendor
    Forms!frmPartsAdditionForm.txtPartNumber = Forms!frmReceivingFormHeader!subfrmReceivingFormDetail!Form.cboPartNumber

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
remove this two lines of codes from above

 Forms!frmPartsAdditionForm.txtVendor = Forms!frmReceivingFormHeader!cboVendor
    Forms!frmPartsAdditionForm.txtPartNumber = Forms!frmReceivingFormHeader!subfrmReceivingFormDetail!Form.cboPartNumber

and paste them in the LOAD event of form "frmPartsAdditionForm"
I'm assuming that the modal form will be used for data entry and you are trying to populate certain data fields.  If that is the case, I would do it differently.  I really don't like to dirty a record when I open a form for adding records.  If the user changes his mind, I now have a dirty record that will either get saved "empty" if there are no constraints or the user will get error messages regarding missing data which will only confuse him.  Instead, I would not populate the fields until the user has actually started typing.  Therefore, I would move the code to the BeforeInsert event.  This event runs ONCE, immediately after you type the first character into ANY control.  I would also lock the two controls this code populates so the user doesn't accidentally overwrite or erase them.

The advantage of this method in addition to what I already mentioned is that the modal form can be used to input multiple records and EACH new record will be correctly populated with the data from the base form.  Using the LOAD event, only the FIRST record would have the fields automatically filled so you would not ever be able to add multiple records unless you allowed the user to type into the foreign key fields on the second and subsequent records.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveL13Author Commented:
Great advice.  Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.