MS Access: Run a code after returning to a form

I have a main form that has controls on it. It has a custom Search button that when clicked opens another form to search specific record. After closing the search form, I would like to perform some validations and tasks before moving to the record that was picked from the search form.

I tried putting this code in the main form gotfocus event but it did not work (may be because it has controls). Also I tried the activate event with no luck.

Where can I put such validation code before moving to the picked record?

Main form is open all the time.
Shadi SalehAsked:
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.

Fabrice LambertFabrice LambertCommented:

You can open the 2nd form in modal (or dialog) mode, this way, once you close it, the execution flow will resume after the line openning it.
Dim i As Integer

docmd.OpenForm "myForm",  windowmode:=acDialog

    '// the line below will be executed after the form is closed
i = 10;

Open in new window


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
Shadi SalehAuthor Commented:
Thanks Fabrice,

Unfortunately, it did not work for me.

After investigations, I can see that acDialog does not work with acFormDS which is my form view.

As a work around I designed a new form as a acNormal form and embedded the DS form as a subform.

And this did the trick.

I will mark your solution as the best, but please add these notes to it.

Thank you!
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.