I have a login form with a password. What I want to do is if/when all other forms/reports are closed on the db, I want the login form to open. What do I have to do to make this happen. Any help would be so much appreciated.
1. In a Standard Module, create this function (replace Frm_Login with the name of your login form):
Public Function OpenLogin(FormName As String) As Long
Dim frm As Form
Dim lngCount As Long
For Each frm In Forms
If frm.Name <> FormName Then
lngCount = lngCount + 1
If lngCount = 0 Then DoCmd.OpenForm "Frm_Login"
OpenLogin = lngCount
2. In the Class Module of every form, except the login form, add this event handler for the Close event:
Private Sub Form_Close()
This worked great...but I forgot one thing. I also need it to close the Switchboard when the data entry form is closed. I need just the Login form to be open. Hoping you can help me with that also. Thanks soooo much!
Using Access 2007. Here's what I want to do. I have a login and if a password is entered correctly, it will take you to 'switchboard'. This is the switchboard for the front office. From here, the front office can open 'dataentry'.
If you don't enter a password in the login, it will open 'switchboard2'. This is the switchboard for security. From here security opens 'dataentry2'.
I don't want security to be able to make changes to the database so I've created two ways to log in with two separate forms - one is called 'dataentry' and the other is called 'dataentry2'. Both dataentry and dataentry2 are linked to the same table called 'masterlist'. So, both forms are seeing the same info but only the front office can make changes to the masterlist through 'dataentry'.
As far as I know, a Switchboard is a form, hence it is present in the Forms collection of the application when it is open. It will then be detected by the Function OpenLogin() which will close it as any other open form.