First event of a Database (1 Viewer)

KitaYama

Well-known member
Local time
Tomorrow, 06:30
Joined
Jan 6, 2022
Messages
1,489
To execute a function as soon as a database opens, I added a RunCode to the top of Autoexec macro.
To my surprise, Autoexec wasn't the first.
On_Open event of the first form (Current database option : Display form) was triggered before autoexec macro.

Is there anywhere else (prior to first form's on_open event) to use as the first event of a database?

Thank you.
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 21:30
Joined
Feb 19, 2013
Messages
16,553
remove your form from display form in current database and add an openform to the autoexec macro to open it after the other autoexec code instructions have executed
 

KitaYama

Well-known member
Local time
Tomorrow, 06:30
Joined
Jan 6, 2022
Messages
1,489
remove your form from display form in current database and add an openform to the autoexec macro to open it after the other autoexec code instructions have executed
Thanks for the advice.
I don't care the autoexec is the first or the form. I just need to run a function as soon as a database opens and before any other actions.
Can I assume the On_Open event of the form is the first?

thanks again.
 

KitaYama

Well-known member
Local time
Tomorrow, 06:30
Joined
Jan 6, 2022
Messages
1,489
see this link
I'm sorry. It seems I wasn't clear enough. I know the order of a form events. I'm looking for the order of a database events.
I try to explain my question :

Until now I thought when I open a database it's what happens:
Autoexec -> Opening of the first form.

But it seems I've been wrong all these years. It's actually is :
Opening of the first form -> Autoexec

Now my question:
Is there anything that happens prior to the opening of the first form (set in options) that I'm not aware of?

thank you.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:30
Joined
Feb 28, 2001
Messages
27,001
According to this, the first thing that runs SHOULD be the Autoexec macro.


There is a note in there that suggests that you COULD also just have an opening form and skip the opening macro.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 21:30
Joined
Feb 19, 2013
Messages
16,553
Now my question:
Is there anything that happens prior to the opening of the first form (set in options) that I'm not aware of?
No
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:30
Joined
Feb 28, 2001
Messages
27,001
I'll see if there is something else, but I'm going to suggest putting your "immediate startup" functions in a startup form and doing away with the macro - or running it from the form.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:30
Joined
Oct 29, 2018
Messages
21,358
Just a thought, try it with a custom ribbon.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:30
Joined
Feb 19, 2002
Messages
42,976
Why would you have BOTH an AutoExec and an opening form. Just use one or the other and avoid the confusion. The AutoExec can run your procedure and then open the form. Or the opening form can run the procedure in its open event.
 

KitaYama

Well-known member
Local time
Tomorrow, 06:30
Joined
Jan 6, 2022
Messages
1,489
Why would you have BOTH an AutoExec and an opening form. Just use one or the other and avoid the confusion. The AutoExec can run your procedure and then open the form. Or the opening form can run the procedure in its open event.
Just did it. Deleted the Autoexec and used the form's on_open event.
But it was strange (for me) Autoexec doesn't run first.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:30
Joined
Oct 29, 2018
Messages
21,358
Just did it. Deleted the Autoexec and used the form's on_open event.
But it was strange (for me) Autoexec doesn't run first.
But try this... Rename your db and move it out of your Trusted Folder. Now, when you open it, which one runs first?
 

KitaYama

Well-known member
Local time
Tomorrow, 06:30
Joined
Jan 6, 2022
Messages
1,489
But try this... Rename your db and move it out of your Trusted Folder. Now, when you open it, which one runs first?
None of them. I receive a yellow line bellow ribbon telling me code is stopped with a button to allow running the code
and a security message telling me Autoexec can not be executed. None of them runs.

If click the button, again the form on_Open code runs first and then the Autoexec.
Didn't you expect it?
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 14:30
Joined
Oct 29, 2018
Messages
21,358
None of them. I receive a yellow line bellow ribbon telling me code is stopped with a button to allow running the code
and a security message telling me Autoexec can not be executed. None of them runs.

If click the button, again the form on_Open code runs first and then the Autoexec.
Didn't you expect it?
You could try a simpler experiment to get a better picture. In the Ribbon event, simply display a message box. Do the same for the Form and Autoexec. Then try it again and see which message box you see first.
 

KitaYama

Well-known member
Local time
Tomorrow, 06:30
Joined
Jan 6, 2022
Messages
1,489
@theDBguy I'm trying to follow your #10 suggestion. I have a custom ribbon.

Autoexec calls a function and creates a ribbon.
Login Form is set to be opened (in option)

Still the form's on_open event runs first.
I'm all ears if it wasn't what you meant.
 

Users who are viewing this thread

Top Bottom