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?
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

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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.