First event of a Database (1 Viewer)

theDBguy

I’m here to help
Staff member
Local time
Today, 12:13
Joined
Oct 29, 2018
Messages
19,165
@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.
Yeah, no. I was just saying, if you really wanted to know which event fires first, then try not to get too fancy in manipulating the sequence of events. Simply use MsgBox to indicate which event fired. So, if your Autoexec or Form loads a Ribbon, that modifies the true sequence of events. You could even try this little experiment using a new blank database with just those three simple objects: custom ribbon, empty form, and autoexec macro.

I'll give you a hint though, you already know the answer. Except, when you try the last test I mentioned above, you might reconsider which event you would use in your app.

Cheers!
 

KitaYama

Active member
Local time
Tomorrow, 04:13
Joined
Jan 6, 2022
Messages
537
Yeah, no. I was just saying, if you really wanted to know which event fires first, then try not to get too fancy in manipulating the sequence of events. Simply use MsgBox to indicate which event fired. So, if your Autoexec or Form loads a Ribbon, that modifies the true sequence of events. You could even try this little experiment using a new blank database with just those three simple objects: custom ribbon, empty form, and autoexec macro.

I'll give you a hint though, you already know the answer. Except, when you try the last test I mentioned above, you might reconsider which event you would use in your app.

Cheers!
It was exactly how I tested which event is fired first. I added a msgbox to Autexec and another one to On_Open of the form.
On_Open of the form was first. Then I had the message from Autoexec .

I'll try your last suggestion (using a blank database) as soon as I'm back to my desk. It's 2AM and I need a rest.
I'll check tomorrow morning (this morning?) and report back.
Thanks again for taking your time and helping.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 20:13
Joined
Sep 12, 2006
Messages
14,901
I would leave the form to open in the database settings as blank.
Do everything you want to check and setup in the autoexec function and then

docmd.openform "myfirstform"

I didn't actually realise the open with form opened before the autoexec macro run. Or maybe I did a long while ago, which is why I leave it blank.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:13
Joined
Feb 19, 2002
Messages
36,871
Doesn't make any sense to have both an Autoexec and an opening form.
 

Mike Krailo

Active member
Local time
Today, 15:13
Joined
Mar 28, 2020
Messages
631
I only use the open form option on simple personal databases or demos. For the actual application for business or client, it is always the autoexec. What Pat said multiple times is true, pick one or the other method.

But the original question is misleading, there is no such thing as a database event when you open it as far as I know. Regardless whether there is zero or a hundred objects in it, you have four options.
  1. Do nothing and the database opens the Access application window and you have to manually open objects from Nav Pane.
  2. Use the simple open form or report option in the settings.
  3. Use the Autoexec instead.
  4. Optionally, use a custom ribbon which is very similar to option #1 if nothing is forced to open right away except now it is completely controlled and the Nav Pane is not used.
So the very first thing that opens is the Access application window, which can as DBGuy suggested have a custom ribbon installed so I think that is what KitaYama was trying to determine. The custom ribbon will load first, then a user can open the things they want directly from the ribbon and then the normal events come into play. You could still use the Autoexec to say run a special form in the background that is hidden/visible at startup.
 

KitaYama

Active member
Local time
Tomorrow, 04:13
Joined
Jan 6, 2022
Messages
537
But the original question is misleading, here is no such thing as a database event
And I say you didn't understand the question. The title may be somehow strange, but the question itself shows what I meant by that title.

I didn't say there's a database event. I asked what will first happen when you open a database. Because according to my tests, it's not auteexec macro. It's the on-open event of the form that is set in option.
It IS the result of my tests. And I asked if there's anything else before that, something that I'm not aware of.
 
Last edited:

KitaYama

Active member
Local time
Tomorrow, 04:13
Joined
Jan 6, 2022
Messages
537
The custom ribbon will load first,
It's wrong. If you load your ribbon from sys table it may be true. I'm not sure because I never do that.

If you load your ribbon from a custom table with vba to construct the xml code and have full power over what will be shown, what will be hidden with very extreme abilities using vba (custom icons etc) , ribbon will not be the first. Again according to my tests it is the on-open form set in options.

It was the main reason I started this thread because I need to load my ribbon as soon as possible (through vba).
 
Last edited:

KitaYama

Active member
Local time
Tomorrow, 04:13
Joined
Jan 6, 2022
Messages
537
Doesn't make any sense to have both an Autoexec and an opening form.
Thanks for your advice.
I followed your suggestion and moved the content of AutoExec to the On_Open form of login form. (the first form to be opened set in options)

Now my LoadRibbons function (to build a custom ribbon) is run from On_Open event of frmLogin.

But it caused additional problems that ended up to this question.
This is the situation:
  1. Someone launches the database. fLogin form opens, create the ribbon and do several other jobs.
  2. User logs in with his/her credential. Does his/her job. click logs out.
  3. Another user clicks login from ribbon to log in and do something else. But as soon as the frmlogin loads he receives an error. Because custom ribbon is already loaded and running LoadRibbons in On_Open event fails. That was why I asked how I can check if a custom ribbon is already loaded.
Not that I'm complaining your comment ended up with another problem. I sincerely appreciate your input and I'm sure your suggestion is the best for sure. That was why I followed it. I'm just saying I'm following your advice and solving every problem one by one.

By the way I ended up removing the form from options (per your advice), Used autoexec to build the ribbon and then opened the login form.

Now everything is fixed and working great.
Thanks again for your time and help.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:13
Joined
Feb 19, 2013
Messages
14,695
Have you looked at options>currentdatabase-ribbon and toolbar options?
 

Mike Krailo

Active member
Local time
Today, 15:13
Joined
Mar 28, 2020
Messages
631
Another user clicks login from ribbon to log in and do something else. But as soon as the frmlogin loads he receives an error. Because custom ribbon is already loaded and running LoadRibbons in On_Open event fails. That was why I asked how I can check if a custom ribbon is already loaded.
Why not leave the login form always loaded in the background. If you don't want to see it, just turn visible property off/on as needed.

But I'm a little confused why you would use form open to load the ribbon. I would put that in autoexec and not use the open form option at all. That way the first thing to load is the ribbon and you can open the login form right after that, as was suggested earlier in the thread. The login form should not load the ribbon IMO. The ribbon should be the very first thing to load.

BTW, in my post about your question being misleading, I should have referred to the thread title (First event of a database). No big deal though.
 

KitaYama

Active member
Local time
Tomorrow, 04:13
Joined
Jan 6, 2022
Messages
537
I would put that in autoexec and not use the open form option at all. That way the first thing to load is the ribbon and you can open the login form right after that, as was suggested earlier in the thread
It's what I'm doing now per given advices. thanks for your input and help.

I should have referred to the thread title (First event of a database). No big deal though.
I couldn't think of a better way to shorten what I'm trying to ask. I thought the contents of the question clears the situation.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:13
Joined
Feb 19, 2002
Messages
36,871
  1. Another user clicks login from ribbon to log in and do something else. But as soon as the frmlogin loads he receives an error. Because custom ribbon is already loaded and running LoadRibbons in On_Open event fails. That was why I asked how I can check if a custom ribbon is already loaded.
The only way that would happen is if the users are opening the same physical copy of the FE. Are they?

Every user MUST have his own personal copy of the FE. The FE should never be shared.

I'm not saying that opening a form is superior to the Autoexec, only that you don't need both of them. I always use a form and I never use the autoexec. It is a relic from before the days when you could specify which form to open.
 

Mike Krailo

Active member
Local time
Today, 15:13
Joined
Mar 28, 2020
Messages
631
How about "How do I force something to occur first?"
It is a relic from before the days when you could specify which form to open.
You mean couldn't, right? In any case, the advantage of Autoexec is clearly that you can do something before any form opens if required and in this case loading that ribbon is a good reason.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:13
Joined
Feb 19, 2002
Messages
36,871
One user should not affect what happens to another user. That can only happen if they are both opening the same physical copy of the FE and we all know enough to never do that.
 

KitaYama

Active member
Local time
Tomorrow, 04:13
Joined
Jan 6, 2022
Messages
537
The only way that would happen is if the users are opening the same physical copy of the FE. Are they?

Every user MUST have his own personal copy of the FE. The FE should never be shared.
I don't know what you mean by share.
We have more than 150 personal here and we don't give them everyone a PC. It's not possible, both financially and space.
Some users have their own PCs but not every one.

We have a lot of PCs located in different places and they work as a terminal. The FE is running on these PCs. Each PC has a local copy.
Those who need to use the database, login with their credentials, do their job, and log out.

I don't see anything wrong with this.
It's shared PC not shared FE.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:13
Joined
Feb 19, 2002
Messages
36,871
The error indicates that the database is being opened by two people at the same time. Otherwise, how would user 2 know that user 1 had loaded a ribbon?

Are you using remote desktop or Citrix? Perhaps they are not set up correctly to ensure that each user gets a separate copy of the FE.
 

KitaYama

Active member
Local time
Tomorrow, 04:13
Joined
Jan 6, 2022
Messages
537
Pat I think you didn't understand what I explained in #28 post. Or I failed to explain it clearly.

First of all, as I explained above, my problem is solved (by moving everything to Autoexec and deleting the form in options to be opened first)
Secondly, no we don't use remote desktop or citrix. It's all on a local network managed by Active Directory.
And as the last point, user 2 doesn't know user 1 has loaded a ribbon. I try to explain it again.

Note : It is the situation when I had the problem and started the thread.
  1. Someone launches the database. frmLogin form opens. create the ribbon and do several other jobs.
  2. User logs in with his/her credential. Does his/her job. click logs out.
  3. All tempvars get deleted, a form with company's logo appears. The database waits for someone else to try to use it.
    Access is running. The database is opened. But nobody has logged in yet. Custom ribbon is sitting there, l
  4. Now someone else (User2) stands in front of PC. clicks login button from ribbon to log in and do something else. But as soon as the frmlogin loads he receives an error. Why? Because custom ribbon is already loaded when the first user opened the database. And LoadRibbons function has been executed once.
I really appreciate you and others who helped.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:13
Joined
Feb 19, 2002
Messages
36,871
I understand that moving everything to autoexec fixed the problem. But the problem wasn't being caused by running the code in a form. The problem was being caused in the the login form because the database was already opened by someone else so the code had already run. That's what needs to be clear. If the database had been closed between users, the issue would never have arisen.

Now that we know you are using a Kiosk operation, we can give better advice. In this case, since you want the db to remain open rather than closing, you need to use an event that is only going to be run once - ever. Therefore moving the code to the AutoExec makes sense because that code only runs once when the database opens.

I've never run into this issue because I actually open a different form from the Login when the db opens. This preliminary form checks on the BE to make sure the connection is valid. This form hides itself then opens the login form. So all the one-time only code happened in the prior form. So, reopening the login form, which happens under some circumstances, doesn't cause a problem. Also, the first form open is the last form to close (because I leave it open and hidden) so that is the form I use to create my automatic backups of the FE during testing.
 

Users who are viewing this thread

Top Bottom