Running sub when returning to open form

G

Guest

I have an unbound "main" form that opens when the database opens. It
contains an option group and two buttons. Clicking a button on this form
opens other pop-up, modal forms, any of which can return the user to the Main
form upon closing.

There is a subroutine that determines what radio buttons should be active
that I need to run (1) when the form opens (no big deal) and (2) each time
the user returns to the main form, which is left open. What Main form event
do I use to do this? I've expiramented with Activate, GotFocus and Current.
All of these fire when the form is loaded, but none fire when focus returns
to the Main form after closing one of the others.

How do trap a return to the main form?

Thanks,
Bruce
 
M

Marshall Barton

BruceS said:
I have an unbound "main" form that opens when the database opens. It
contains an option group and two buttons. Clicking a button on this form
opens other pop-up, modal forms, any of which can return the user to the Main
form upon closing.

There is a subroutine that determines what radio buttons should be active
that I need to run (1) when the form opens (no big deal) and (2) each time
the user returns to the main form, which is left open. What Main form event
do I use to do this? I've expiramented with Activate, GotFocus and Current.
All of these fire when the form is loaded, but none fire when focus returns
to the Main form after closing one of the others.

How do trap a return to the main form?


There isn't an event for this. Well, maybe Activate, but
you said it doesn't work in your case.

The usual way to do this kind of thing is to open the other
forms in Dialog mode, then place your code immediately after
the OpenForm line.

If you can't do that, the only other way I can think of is
to have the other forms call the "main" form's procedure:
Forms!main.procedurename
 
G

Guest

Marsh,

That one should have occurred to me...Amazing how we get wrapped up in what
Access "will not" do. (See below.)

I put the procedure call in the main form's OnTimer event, then set the
TimerInterval to 10 just before closing the pop-ups. I'll change to the code
to use the direct procedure call. Much more elegant.

Simple is better...

BTW, per Access Help:

"The Activate event doesn't occur when a form receives focus back from a
dialog box, popup, or another form."

"If a form contains any visible, enabled controls, the GotFocus event for
the form doesn't occur."

Thanks,
Bruce
 
G

Guest

Marsh,

Tried you suggestion, but I get a RTE 2465 "Applicaton-defined or
object-defined error."

In closing the pop-ups, tried changing both the order of statements and the
syntax, e.g.:
....
DoCmd.Close
Forms![Welcome].InitializeData
End Sub

and

....
Forms!Welcome.InitializeData
DoCmd.Close
End Sub

The called sub sets focus on controls on the Welcome form. Works fine when
I call it in Form_Load.

Any ideas?

Tks,
Bruce
 
M

Marshall Barton

What line is highlightes when the error occurs?

Maybe the focus can't be taken away from a modal form? Why
do you need to set it?
--
Marsh
MVP [MS Access]

Tried you suggestion, but I get a RTE 2465 "Applicaton-defined or
object-defined error."

In closing the pop-ups, tried changing both the order of statements and the
syntax, e.g.:
...
DoCmd.Close
Forms![Welcome].InitializeData
End Sub

and
...
Forms!Welcome.InitializeData
DoCmd.Close
End Sub

The called sub sets focus on controls on the Welcome form. Works fine when
I call it in Form_Load.


Marshall Barton said:
There isn't an event for this. Well, maybe Activate, but
you said it doesn't work in your case.

The usual way to do this kind of thing is to open the other
forms in Dialog mode, then place your code immediately after
the OpenForm line.

If you can't do that, the only other way I can think of is
to have the other forms call the "main" form's procedure:
Forms!main.procedurename
 
G

Guest

Marsh,

The Forms!Welcome.InitializeData statement is highlighted.

InitializeData runs two subroutines that query for data to set various
variables, then performs a number of logical tests on those values.
Depending upon the results, it enables/disables members of the option group
and one of the two buttons.

In my code, I move the the focus to button 1 to be sure that I can disable
button 2, and set the option value to a default that is never disabled so
that I can disable the other options, if needed. If all tests are OK, I
enable button 2 and set focus there.

(the short answer) Yes, I need to set the focus. If you're out of ideas, I
can go back to the "timer" method. Not as elegant, though...

As always, thanks for being there!
Bruce

Marshall Barton said:
What line is highlightes when the error occurs?

Maybe the focus can't be taken away from a modal form? Why
do you need to set it?
--
Marsh
MVP [MS Access]

Tried you suggestion, but I get a RTE 2465 "Applicaton-defined or
object-defined error."

In closing the pop-ups, tried changing both the order of statements and the
syntax, e.g.:
...
DoCmd.Close
Forms![Welcome].InitializeData
End Sub

and
...
Forms!Welcome.InitializeData
DoCmd.Close
End Sub

The called sub sets focus on controls on the Welcome form. Works fine when
I call it in Form_Load.

BruceS wrote:
I have an unbound "main" form that opens when the database opens. It
contains an option group and two buttons. Clicking a button on this form
opens other pop-up, modal forms, any of which can return the user to the Main
form upon closing.

There is a subroutine that determines what radio buttons should be active
that I need to run (1) when the form opens (no big deal) and (2) each time
the user returns to the main form, which is left open. What Main form event
do I use to do this? I've expiramented with Activate, GotFocus and Current.
All of these fire when the form is loaded, but none fire when focus returns
to the Main form after closing one of the others.

How do trap a return to the main form?

Marshall Barton said:
There isn't an event for this. Well, maybe Activate, but
you said it doesn't work in your case.

The usual way to do this kind of thing is to open the other
forms in Dialog mode, then place your code immediately after
the OpenForm line.

If you can't do that, the only other way I can think of is
to have the other forms call the "main" form's procedure:
Forms!main.procedurename
 
M

Marshall Barton

You did remember to make the InitializeData procedure
Public, right?

Hmmm ... I am out of ideas, but what happens if you comment
out the setFocus?
--
Marsh
MVP [MS Access]

The Forms!Welcome.InitializeData statement is highlighted.

InitializeData runs two subroutines that query for data to set various
variables, then performs a number of logical tests on those values.
Depending upon the results, it enables/disables members of the option group
and one of the two buttons.

In my code, I move the the focus to button 1 to be sure that I can disable
button 2, and set the option value to a default that is never disabled so
that I can disable the other options, if needed. If all tests are OK, I
enable button 2 and set focus there.

(the short answer) Yes, I need to set the focus. If you're out of ideas, I
can go back to the "timer" method. Not as elegant, though...


Marshall Barton said:
What line is highlightes when the error occurs?

Maybe the focus can't be taken away from a modal form? Why
do you need to set it?

Tried you suggestion, but I get a RTE 2465 "Applicaton-defined or
object-defined error."

In closing the pop-ups, tried changing both the order of statements and the
syntax, e.g.:
...
DoCmd.Close
Forms![Welcome].InitializeData
End Sub

and
...
Forms!Welcome.InitializeData
DoCmd.Close
End Sub

The called sub sets focus on controls on the Welcome form. Works fine when
I call it in Form_Load.


BruceS wrote:
I have an unbound "main" form that opens when the database opens. It
contains an option group and two buttons. Clicking a button on this form
opens other pop-up, modal forms, any of which can return the user to the Main
form upon closing.

There is a subroutine that determines what radio buttons should be active
that I need to run (1) when the form opens (no big deal) and (2) each time
the user returns to the main form, which is left open. What Main form event
do I use to do this? I've expiramented with Activate, GotFocus and Current.
All of these fire when the form is loaded, but none fire when focus returns
to the Main form after closing one of the others.

How do trap a return to the main form?


:
There isn't an event for this. Well, maybe Activate, but
you said it doesn't work in your case.

The usual way to do this kind of thing is to open the other
forms in Dialog mode, then place your code immediately after
the OpenForm line.

If you can't do that, the only other way I can think of is
to have the other forms call the "main" form's procedure:
Forms!main.procedurename
 
G

Guest

Just call me "Forest". Was Private vs. Public. Works great, now!

Thanks, Marsh.

Bruce

Marshall Barton said:
You did remember to make the InitializeData procedure
Public, right?

Hmmm ... I am out of ideas, but what happens if you comment
out the setFocus?
--
Marsh
MVP [MS Access]

The Forms!Welcome.InitializeData statement is highlighted.

InitializeData runs two subroutines that query for data to set various
variables, then performs a number of logical tests on those values.
Depending upon the results, it enables/disables members of the option group
and one of the two buttons.

In my code, I move the the focus to button 1 to be sure that I can disable
button 2, and set the option value to a default that is never disabled so
that I can disable the other options, if needed. If all tests are OK, I
enable button 2 and set focus there.

(the short answer) Yes, I need to set the focus. If you're out of ideas, I
can go back to the "timer" method. Not as elegant, though...


Marshall Barton said:
What line is highlightes when the error occurs?

Maybe the focus can't be taken away from a modal form? Why
do you need to set it?


BruceS wrote:
Tried you suggestion, but I get a RTE 2465 "Applicaton-defined or
object-defined error."

In closing the pop-ups, tried changing both the order of statements and the
syntax, e.g.:
...
DoCmd.Close
Forms![Welcome].InitializeData
End Sub

and
...
Forms!Welcome.InitializeData
DoCmd.Close
End Sub

The called sub sets focus on controls on the Welcome form. Works fine when
I call it in Form_Load.


BruceS wrote:
I have an unbound "main" form that opens when the database opens. It
contains an option group and two buttons. Clicking a button on this form
opens other pop-up, modal forms, any of which can return the user to the Main
form upon closing.

There is a subroutine that determines what radio buttons should be active
that I need to run (1) when the form opens (no big deal) and (2) each time
the user returns to the main form, which is left open. What Main form event
do I use to do this? I've expiramented with Activate, GotFocus and Current.
All of these fire when the form is loaded, but none fire when focus returns
to the Main form after closing one of the others.

How do trap a return to the main form?


:
There isn't an event for this. Well, maybe Activate, but
you said it doesn't work in your case.

The usual way to do this kind of thing is to open the other
forms in Dialog mode, then place your code immediately after
the OpenForm line.

If you can't do that, the only other way I can think of is
to have the other forms call the "main" form's procedure:
Forms!main.procedurename
 
M

Marshall Barton

Details, details, details. What business does a little
detail like that have preventing an application from
running ;-)

Glad to hear you're back on track now.
--
Marsh
MVP [MS Access]

Just call me "Forest". Was Private vs. Public. Works great, now!

Thanks, Marsh.


Marshall Barton said:
You did remember to make the InitializeData procedure
Public, right?

Hmmm ... I am out of ideas, but what happens if you comment
out the setFocus?

The Forms!Welcome.InitializeData statement is highlighted.

InitializeData runs two subroutines that query for data to set various
variables, then performs a number of logical tests on those values.
Depending upon the results, it enables/disables members of the option group
and one of the two buttons.

In my code, I move the the focus to button 1 to be sure that I can disable
button 2, and set the option value to a default that is never disabled so
that I can disable the other options, if needed. If all tests are OK, I
enable button 2 and set focus there.

(the short answer) Yes, I need to set the focus. If you're out of ideas, I
can go back to the "timer" method. Not as elegant, though...


:
What line is highlightes when the error occurs?

Maybe the focus can't be taken away from a modal form? Why
do you need to set it?


BruceS wrote:
Tried you suggestion, but I get a RTE 2465 "Applicaton-defined or
object-defined error."

In closing the pop-ups, tried changing both the order of statements and the
syntax, e.g.:
...
DoCmd.Close
Forms![Welcome].InitializeData
End Sub

and
...
Forms!Welcome.InitializeData
DoCmd.Close
End Sub

The called sub sets focus on controls on the Welcome form. Works fine when
I call it in Form_Load.


BruceS wrote:
I have an unbound "main" form that opens when the database opens. It
contains an option group and two buttons. Clicking a button on this form
opens other pop-up, modal forms, any of which can return the user to the Main
form upon closing.

There is a subroutine that determines what radio buttons should be active
that I need to run (1) when the form opens (no big deal) and (2) each time
the user returns to the main form, which is left open. What Main form event
do I use to do this? I've expiramented with Activate, GotFocus and Current.
All of these fire when the form is loaded, but none fire when focus returns
to the Main form after closing one of the others.

How do trap a return to the main form?


:
There isn't an event for this. Well, maybe Activate, but
you said it doesn't work in your case.

The usual way to do this kind of thing is to open the other
forms in Dialog mode, then place your code immediately after
the OpenForm line.

If you can't do that, the only other way I can think of is
to have the other forms call the "main" form's procedure:
Forms!main.procedurename
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top