Action when DB Closes

ChampionDuy

Registered User.
Local time
Today, 08:39
Joined
Mar 14, 2002
Messages
94
I have a table that lets me know what users are loged into my database. In that table whenever a user logs in, the YES/NO field for that user changes from a No to a Yes.

I need that field to return to a NO, whenever that user exits the DB.

I have a button that I have told all users to use to Exit the DB. This button exits the DB and runs a query that changes the field to NO.

However we all know users, and they rarely do what is told. And if they wanted, they could still go to File, Exit. (Unless someone could tell me how to get rid of that) Or they could still click on the "X" in the top right hand corner. (Unless someone could tell me how to get rid of that) How can I either force them to use the Exit button, or have that query run whenever a the DB closes.

Is there a DB close event?

Where would I put the code to run the Query?
 
Any way to keep a user from using the File, Exit? Is there anyway to get that entire toolbar to disappear?
 
Turn off the menus under Tools -> Startup
 
Let me rephrase my quesiton. I have disabled everything on the users forms and through the Startup options. But the toolbar still allows for the File Exit and the Edit and Help and some other things. Anyway to get rid of all of that?
 
Don't know but, if you look at that example I posted on the thread I linked to then the user can't exit the database by selecting File -> Exit
 
Thank you very much, Gotta get back to work now. These forums are great. Very helpfull.
 
That's an excellent piece of code, MoP. I copied your db, and even without the autoexec, it's almost uncanny (to we of litttle experience) how the user has to use the stipulated button. Many thanks
 
The only one thing I can't stop is quitting the database with Task Manager. :mad:
 
What an admission! But I'll happily use it even so. Cheers.
 
ChampionDuy, be keen to see how your Yes/No arrangement works. Mile-O-Philes' code is perfect for ensuring the right button only is used.
 
Yes/No

I have a form where the user enters in his/her user name and password. Then clicks enter. The code then searches the table tblPasswords to see if the user name and passowrd are correct. If it is, then the user is granted access to the system and a query is run to update the field inside the table to YES. WHen the user hits the exit button the field is set back to NO.

If the username and password are incorrect then the user is denied access and no queries are run.

I will attach the example. Let me know what you think. I am not the best programmer. Of course if you want to incorporate it into one of your applications you will have to change some of the form names in the code. But not much.

The user name is BGates
The Password is password
 
ChampionDuy
A quick look through and it is most impressive. Will have a good look when I get a chance later on. Be very pleased to play with this one - and learn from it. Quite amazing to see MoP's module there. It goes well with your set-up. Many thanks, Brian.
Cheers
Paul
 
Query --> Execute

ChampionDuy,
I had a chance to review your login.mdb and for this forum its understandably basic, but when loging in and out your code is running an the related Update Queries for indicating who's logged in and out. I don't know if you noticed but a message box pops up asking for OK that the Update take place. This is probably not appropriate for your users to handle.
' query that sets the In/Out field to yes to show that the user is loged into the database. Utility that is used to show what users are logged into the Database
stDocName = "qryLogIN"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Consider changing this to an Execute method:

CurrentDb.Execute "UPDATE tblPasswords SET tblPasswords.[In/Out] = Yes WHERE [username]='" & CurrentUser & "';"

and the same for loging out:

CurrentDb.Execute "UPDATE tblPasswords SET tblPasswords.[In/Out] = No WHERE [username]='" & CurrentUser & "';"

I've already done everything you've mentioned doing or are showing in your sample db so if you have more questions or ideas feel free to ask.
 
Go to tools, options, edit/find tab. Unckeck the confirm boxes and you will no longer get the question if you want the update to execute.
 
Last edited:
ChampionDuy said:
Go to tools, options, edit/find tab. Unckeck the confirm boxes and you will no longer get the question if you want the update to execute.


It's a better practice not to turn these off - you may need mesages like that to be displayed.

It's better to surround either side of the SQL execution with the DoCmd.SetWarnings command.


i.e.

Code:
DoCmd.SetWarnings False
CurrentDb.Execute "UPDATE tblPasswords SET tblPasswords.[In/Out] = Yes WHERE [username]='" & CurrentUser & "';"
DoCmd.SetWarnings True
 
setwarnings command

Yes, turning off the message prompts is not recomended nor feasable on a distrubuted app to lots of users. Solution, write better code.

In this case and other cases where you don't care about the Execute method result completing with or without errors then the setwarnings command is fine but most case you need to know if an error was incurred during the attempted update and inform the user that the data was not updated and you need to handle the error some how. Then you would need to use normal error trapping proceedures to better handle the event.
 
Last edited:
Like I said in the earlier post. I am not a very good programmer. Thanks for you help.
 

Users who are viewing this thread

Back
Top Bottom