Solved

controling the termination of a form

Posted on 2000-02-24
4
119 Views
Last Modified: 2010-05-02
Hi

How can I disbale user from pressing on the [x] button (on the upper-right side of the form).

Thanks,

Liron Golan
0
Comment
Question by:lirong
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 5 total points
ID: 2555474
"HOWTO: Disable the Close Option on Control Menu of a VB Form"

http://support.microsoft.com/support/kb/articles/Q184/6/86.ASP
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2555524
Or:

Option Explicit

Const MF_REMOVE = &H1000&
Const MF_BYPOSITION = &H400&

Private Declare Function GetSystemMenu Lib "user32" _
    (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" _
    (ByVal hMenu As Long) As Long
Private Declare Function RemoveMenu Lib "user32" _
    (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long

Private Sub Form_Load()
    Dim hMenu As Long
    Dim menuItemCount As Long
    'Obtain the handle to the form's system menu
    hMenu = GetSystemMenu(Me.hwnd, 0)
    If hMenu <> 0 Then
        'Obtain the number of items in the menu
        menuItemCount = GetMenuItemCount(hMenu)
        'Remove the system menu Close menu item.
        'The menu item is 0-based, so the last
        'item on the menu is menuItemCount - 1
        Call RemoveMenu(hMenu, menuItemCount - 1, _
            MF_REMOVE Or MF_BYPOSITION)
        'Remove the system menu separator line
        Call RemoveMenu(hMenu, menuItemCount - 2, _
            MF_REMOVE Or MF_BYPOSITION)
    End If
End Sub

Private Sub Command1_Click()
    Unload Me
End Sub
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2556642
This is to prevent the user from using the control menu or the close button.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode = vbFormControlMenu Then Cancel = 1
End Sub
0
 
LVL 1

Expert Comment

by:HunterKiller
ID: 2561340
I can also set the form property ControlBox to False
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

775 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