Actions when closing down an Access Database

Robert2150

New member
Local time
Today, 11:28
Joined
Jan 19, 2012
Messages
4
I have a Microsoft Access Database loaded on a Microsoft Server that multiple users have access to.
Is there anyway to automatically sign the user off the Server when they close the Database?
 
If the FE signs the users on to the server when it opens, it can sign them off in the Close event of the menu or whatever form closes last. I use a login form and when the user successfully logs in, I open the switchboard but instead of closing the login form, I hide it. Therefore, the single form is used for both login and logout events.
I may not have been clear on how the Users access the database, they use the RDC (Remote Desktop Connection) with their own user name and password. When they connect through this connection they are connected to the server and the Database opens. Is there anyway to have the user automatically signed off the RDC when they close the database? Thank you.
 
To answer this question from another direction, once you have established a login session, you cannot terminate the login from the application directly because you still have open resources. Like the old Warner Brothers cartoons where you could saw off the tree limb on which you were seated - and have the rest of the tree fall over - that is what you are asking to do. There might well be an API call that you could make to tell the O/S to terminate your session - but you would have to worry about proper closure of all resources first.

Pat's suggestion works because the RDP "shell" will persist after the app exits AND that shell has been set up to terminate when the app closes. That is, there is a persistent instruction somewhere that says "... and then log me out." But if you tried to do it from the Access-based app, there is no place for that persistent instruction to reside once Access closes the app and itself exits.
 
Several years ago I've done it and it's actually possible.

1- In a vba function, save a bat file that contain a ping to a non-existence ip
2- add this line : rwinsta RemoteID
3- execute the bat file you just saved. Shell.Execute the_path_to_Bat.bat
4- Application.Quit to quit Access

Note:
  • The ping is just something to give you enough time to quit Access
  • RemoteID is the ID that the server assigns to the client during the remote desktop connection
  • Your final structure should be something like rwinsta 2. (2 being the ID. In following image I've opened a remote desktop to server with Administrator username.)
If you don't know the remoteID of the connection, in vba write a function to save, execute and export the following command to a text file:
qwinsta /server

This command gives a chart that contains username and ID of all remote desktop connections. Read the text file line by line and when you reach the username, you can get the ID.

I have a script somewhere for this. Though it was years ago, I may have a copy. I'll search.
If I can not find it, search for the commands rwinsta and qwinsta.


2022-07-27_10-42-41.png
 
Last edited:
DOS has the timeout command rather than using ping.
Alternatively, Powershell has -sleep.
 
@KitaYama - That works because you create an environment within your session to contain the command to terminate the session. The shell is a child process of the login session and the Access session vanishes in ITS "child-slice" of the original login.

You can do from the CMD shell far more easily what you cannot do so easily from the VBA environment. And I DID say it was possible from VBA but required you to play games with the WIN32 API. So your suggestion indeed might work for the OP. (y)
 
..... Like the old Warner Brothers cartoons where you could saw off the tree limb on which you were seated - and have the rest of the tree fall over - that is what you are asking to do. ......
I like the branch and tree analogy in this situation
 

Users who are viewing this thread

Back
Top Bottom