Automatically updating a field

I have a form called “Scheduling-Add”. When the patient name is selected from the drop down I want the Date of Birth (if available) for that patient to automatically populate in the “DOB” field My form doesn’t do that now. How can I accomplish this goal. Attached is a copy of my database with the form. Thanks in advance.
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.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Add code like this in the AfterUpdate event of your cmbPatientName:
Me.txtDOB = DLookup("DOB", "Patient", "PatientID=" & Me.cmbPatientName.Column(0))

Open in new window

Also add the same code in the Form_Current event.

Remove the ControlSource value from the DOB textbox.

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
RyanProject Engineer, ElectricalCommented:
Your tables aren't normalized properly to start with.  Without going into great detail, your Scheduling table shouldn't have the patients name in it, but rather the PatientID, which would link to the Patient table, where you can then build their name, and also pull in the DOB.

The way you have it can work, using the DBLookup, but its MUCH slower, and you cannot guarentee you won't have issues with matching patients, if a name is spelled differently, or 2 patients have the same name.

=DLookUp("DOB","Patient","PatientID=[PatientName]") Won't work because Patient ID is a number, whereas PatientName is actually (Patient.LastName & ", " & Patient.FirstName & " " & Patient.MiddleName)

There seems to be other codes running that keeps undoing my changes, so I can't verify that this code works.  Here's the inferior method you can try:

=DLookUp("DOB","Patient","Patient.LastName & ", " & Patient.FirstName & " " & Patient.MiddleName=[PatientName]")
Chrisjack001Author Commented:
Thanks LSMConsulting
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.