Microsoft Access can't find the field 'Customer_Code' refererred to in your expression


I am getting the error "Microsoft Access can't find the field 'Customer_Code' refererred to in your expression"

I am using the following code in the Invoice Detail subform as follows

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
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.

John TsioumprisSoftware & Systems EngineerCommented:
Probably something you missed...most common the text box  was pointing to another field and you changed it to point to the correct one but you forgot to rename the text box
ste5anSenior DeveloperCommented:
The problem is, that Access per default names the control with the column name. And using the bang instructs Access to search in Fields as well as in Controls to resolve your Forms!Invoices!Customer_Code.Text. While this is nice for simple use-cases,

My preferences are

1) rename every control, that you need to use in code.
2) Access only fields with the bang. Using also square brackest for better readability.
3) Access controls only by the dot.

Also don't use the Forms collection. In your scenario it is better to use the Parent:

oCustomerCode = Me.Parent.Form![CustomerCode]

Open in new window

For accessing the field. Or

oCustomerCode = Me.Parent.Form.txtCustomerCode.Value

Open in new window

for reading the controls value.

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
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Great answer. 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.