Is there a way to detect when a particular form is opened?

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

I've got two forms, Form1 and Form2. Form1 opens invisibly when the database opens. From Form1 (or from a regular module or class module accessed by Form1), is there a way to detect when Form2 opens?

I'm restricted to only coding in Form1 (or a regular module or class module accessed by Form1). The code can't be in another Form's module, and can't be in the application's startup module fired by the AutoExec macro. That's already being used for a different purpose.

I know the restriction makes it hard but that's what I have to work with. Please let me know if you know a way. I'll write an add-in if I have to but would rather avoid that.
 
S

Sylvain Lafontaine

The only way that I see would be to set a timer event and use it to check periodically if form2 is open. To my knowledge, there is no way that Access will send a direct event to your form1 when form2 is opened; especially if you can't touch anything else (but I may be wrong, as it's often the case).

For a moment, I have thought about using object with WithEvent (for an exemple, see http://accessadvisor.net/doc/13276 ); but even this require some sort of initialisation code inside the Form2 module.

What is the purpose of your restrictions?

S. L.
I've got two forms, Form1 and Form2. Form1 opens invisibly when the database opens. From Form1 (or from a regular module or class module accessed by Form1), is there a way to detect when Form2 opens?

I'm restricted to only coding in Form1 (or a regular module or class module accessed by Form1). The code can't be in another Form's module, and can't be in the application's startup module fired by the AutoExec macro. That's already being used for a different purpose.

I know the restriction makes it hard but that's what I have to work with. Please let me know if you know a way. I'll write an add-in if I have to but would rather avoid that.
 
S

Sylvain Lafontaine

Another good article on WithEvent, it is about Access 97 but maybe it will shed you some light:
http://smsconsulting.spb.ru/shamil_s/articles/wew.htm

S. L.
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)> wrote in message The only way that I see would be to set a timer event and use it to check periodically if form2 is open. To my knowledge, there is no way that Access will send a direct event to your form1 when form2 is opened; especially if you can't touch anything else (but I may be wrong, as it's often the case).

For a moment, I have thought about using object with WithEvent (for an exemple, see http://accessadvisor.net/doc/13276 ); but even this require some sort of initialisation code inside the Form2 module.

What is the purpose of your restrictions?

S. L.
I've got two forms, Form1 and Form2. Form1 opens invisibly when the database opens. From Form1 (or from a regular module or class module accessed by Form1), is there a way to detect when Form2 opens?

I'm restricted to only coding in Form1 (or a regular module or class module accessed by Form1). The code can't be in another Form's module, and can't be in the application's startup module fired by the AutoExec macro. That's already being used for a different purpose.

I know the restriction makes it hard but that's what I have to work with. Please let me know if you know a way. I'll write an add-in if I have to but would rather avoid that.
 
M

msnews.microsoft.com

Thanks Sylvain,

Timer is good enough for what I'm doing. On the Form_Open event I go Me.TimerInterval = 250 and on the Form_Timer event I go

If IsLoaded("Form2") Then DoCmd.Close acForm, "Form2": Me.TimerInterval = 0

This only happens once just after startup so it's sufficient. Thanks
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)> wrote in message Another good article on WithEvent, it is about Access 97 but maybe it will shed you some light:
http://smsconsulting.spb.ru/shamil_s/articles/wew.htm

S. L.
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)> wrote in message The only way that I see would be to set a timer event and use it to check periodically if form2 is open. To my knowledge, there is no way that Access will send a direct event to your form1 when form2 is opened; especially if you can't touch anything else (but I may be wrong, as it's often the case).

For a moment, I have thought about using object with WithEvent (for an exemple, see http://accessadvisor.net/doc/13276 ); but even this require some sort of initialisation code inside the Form2 module.

What is the purpose of your restrictions?

S. L.
I've got two forms, Form1 and Form2. Form1 opens invisibly when the database opens. From Form1 (or from a regular module or class module accessed by Form1), is there a way to detect when Form2 opens?

I'm restricted to only coding in Form1 (or a regular module or class module accessed by Form1). The code can't be in another Form's module, and can't be in the application's startup module fired by the AutoExec macro. That's already being used for a different purpose.

I know the restriction makes it hard but that's what I have to work with. Please let me know if you know a way. I'll write an add-in if I have to but would rather avoid that.
 
S

Sylvain Lafontaine

Beware!

A timer of 250 ms might be insufficient in some case if the user open the file but the PC is otherwise very busy at the same time. Usually, when using timer for this kind of work, it is best to repeat the test some times; just to make sure that there has been no exceptional external activities capable of delaying the opening of a form by Access.

S. L.
Thanks Sylvain,

Timer is good enough for what I'm doing. On the Form_Open event I go Me.TimerInterval = 250 and on the Form_Timer event I go

If IsLoaded("Form2") Then DoCmd.Close acForm, "Form2": Me.TimerInterval = 0

This only happens once just after startup so it's sufficient. Thanks
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)> wrote in message Another good article on WithEvent, it is about Access 97 but maybe it will shed you some light:
http://smsconsulting.spb.ru/shamil_s/articles/wew.htm

S. L.
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)> wrote in message The only way that I see would be to set a timer event and use it to check periodically if form2 is open. To my knowledge, there is no way that Access will send a direct event to your form1 when form2 is opened; especially if you can't touch anything else (but I may be wrong, as it's often the case).

For a moment, I have thought about using object with WithEvent (for an exemple, see http://accessadvisor.net/doc/13276 ); but even this require some sort of initialisation code inside the Form2 module.

What is the purpose of your restrictions?

S. L.
I've got two forms, Form1 and Form2. Form1 opens invisibly when the database opens. From Form1 (or from a regular module or class module accessed by Form1), is there a way to detect when Form2 opens?

I'm restricted to only coding in Form1 (or a regular module or class module accessed by Form1). The code can't be in another Form's module, and can't be in the application's startup module fired by the AutoExec macro. That's already being used for a different purpose.

I know the restriction makes it hard but that's what I have to work with. Please let me know if you know a way. I'll write an add-in if I have to but would rather avoid that.
 

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