Exit button on VB Form

Posted on 2004-10-22
Last Modified: 2013-12-26
Is there a way to remove the exit button on a form? I want to force my users to use my exit button because I log them in and out of the application and I don't want them to find a way out of it by using the x button to exit.
Question by:jmoneilthe2
    LVL 18

    Accepted Solution

    Set Controlbox property of the form to false and BorderStyle to Fixed Dialog. Also ensure that no text is entered in the Caption property.
    LVL 32

    Expert Comment

    You can logoff users in the QueryUnload event...

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        If (UnloadMode = vbFormControlMenu) Or (UnloadMode = vbFormCode) Then
            'Catch both unloading from code (menu) and from [X] button
            Debug.Print "Logoff users here"
        End If
    End Sub

    Author Comment

    Excellent. Thank you. This would be better than taking the x out.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Learn The Basics of Ethical Hacking & Pen Testing

    Computer and network security is one of the fastest growing and most essential industries in technology, meaning companies will pay big bucks for ethical hackers. This is the perfect course to leap into this lucrative career, learning how to use ethical hacking to reveal ...

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now