Check last form to be closed and fire event

G

Guest

Is it possible to check if a form has just been closed? I have a form that
has values updated when a related form is closed. I then want to
automatically change other values on the open form. This uses code placed on
a fields before update event which works fine when changed manually but does
not fire when the field is programmatically updated. I have read that I could
call the event in code. I am not sure which event to attach the code to now.
Can I use the got focus event of the form as the second form closes?
Also is it possible to check if the form has just closed and use this as a
condition to run the code so it doesn't run everytime the got focus event
occurs.
I tried to call the before update event in the forms load event to test if
it might work but get an argument not optional error message which I don't
understand. Is there a way to call an event?
I have been really struggling with this and would be very grateful for any
suggestions.
 
M

Mark A. Sam

You can use the Isloaded function to find out if a form is loaded like:

If Not Isloaded "Form Name" then
do something
End If

The Isloaded function can be found in a module in the Northwinds sample
database I believe.

God Bless,

Mark A. Sam
 
G

Guest

Thanks - I found the IsLoaded function as you suggested and tried this.
Unfortunately it appears the form is loaded before the activate event occurs.
I found that using debug.print IsLoaded ("frmName") was true when I put it in
the activate event before the code I want to run. I have also tried IsOpen
but this seems to become true before the activate event.
What I am trying to do is just run the code if I have just closed one
particular form. I thought I had read somewhere that you can check the last
event but now I can't find this information again. Does anyone know if I am
remebering incorrectly or have any idea how else I might achieve a result?
 
M

Mark A. Sam

You can force the form closed like:

DoCmd.Close acForm, Forms("FormName").Name

Then you will be sure it is closed.

You will need to trap error 2450 for the case that the form is not opened.

You can also set a global variable when on the Close or Unload event of the
form being referenced is closed and also set it when the form is opened,
using the Open or Load event.

I'm not really understanding your situation but maybe these methods will
help you.

God Bless,

Mark
 
G

Guest

Thanks again - I have got round it in I think a similar way to your
suggestion. I set a boolean variable to true in the code on the close button
of the updating form and set the value of a check box on the updated form to
represent this. In the updated form's activate event I could then check this
value and run the code only if it is true. I then reset the value to false at
the end of the code being called. The visible property of the check box is
false so the users don't see it. I think it is perhaps clumsy but it does
seem to work. - Once again thanks for your help. These sites and the people
who use them are so helpful.
 
M

Mark A. Sam

Peter.

Just something to be aware of. Becuase the code is on the Close Button,
your method won't run if the user closes the form in another way.

God Bless,

Mark
 

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