Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

controling the termination of a form

Posted on 2000-02-24
4
120 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

789 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