Warning on Logout

awa786

Registered User.
Local time
Today, 05:27
Joined
Jul 7, 2015
Messages
23
Hi all,
I want to write a code that will track that if any form or report is opened or not when user click on the logout button on the Main form (Switchboard) and want to display the message box like this
"Please close all the windows before longing out"

please help me
.
 
Wouldnt all the forms and reports close on a quit command?

You could loop through the forms and reports collection and if the form/report is loaded throw up a message box and exit the sub.
something like...

Code:
    Dim objAccObj As AccessObject
    Dim objTest As Object
    Dim StrOpen As String

    Set objTest = Application.CurrentProject

    For Each objAccObj In objTest.AllForms

        If objAccObj.IsLoaded = True And objAccObj.Name <> Me.Name Then   ' check if form is loaded and not the calling form

            If StrOpen <> "" Then

                StrOpen = StrOpen & "," & objAccObj.Name

            Else

                StrOpen = objAccObj.Name

            End If

        End If

    Next objAccObj


    For Each objAccObj In objTest.AllReports

        If objAccObj.IsLoaded = True And objAccObj.Name <> Me.Name Then   ' check if report is loaded and not the calling form

            If StrOpen <> "" Then

                StrOpen = StrOpen & "," & objAccObj.Name

            Else

                StrOpen = objAccObj.Name

            End If

        End If

    Next objAccObj


    If StrOpen = "" Then               ' if no forms are open then close form

        DoCmd.Close acForm, Me.Name

    Else
        MsgBox "Please close " & StrOpen & " before closing"    ' if there are open forms msgbox names

        Exit Sub

    End If
 
The simplest way to do this is to make the child forms of the switchboard to obscure the logout button. Either make the button invisible while the child is up or make the child maximize itself during Form_Load and make it sit on top of the switchboard so that the logout button isn't visible (and the switchboard isn't the active form). Can't click what you can't see.

Note that of these two solutions, the 2nd is FAR easier to program. Making the logout button go away would require a LOT of event programming depending on how many buttons you have to launch forms. One addition (albeit the same code each time, so could be a subroutine) to disable the logout button for each child form launch, and one addition for for the main form's OnEnter event to enable it when the child form closes.
 

Users who are viewing this thread

Back
Top Bottom