473,324 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How can disable window close button for an MDB file?

23
hi

How can disable window close button for an MDB file. because when a user closes application by clicking on window close button (right top corner), unsaved & incomplete data on the form gets saved in respective table. i want to prevent this from happening.

plz give me a good suggestion

thanx a lot in advance.
Dec 25 '13 #1
4 1546
zmbd
5,501 Expert Mod 4TB
without a lot of work, you don't.

instead you prevent a form from closing as I explained to you here: http://bytes.com/topic/access/answer...on#post3763718

These two questions are basically the same and such threads are occationally deleted on the grounds of double posting.
Dec 25 '13 #2
NeoPa
32,556 Expert Mod 16PB
Sometimes the rules about double-posting and having a single topic per thread can be confusing.

However, whether or not you realise it, these questions do overlap (This one and the one linked in Z's post). The answer is also in that linked thread. Simply have a form that is open and that has Cancel = True in the Form_Unload() event procedure. Handle with care though, of course, as if it is always True then the database will never close!
Dec 26 '13 #3
neelsfer
547 512MB
i use this "call" in the "load" event of the startup form and it seems to work fine. Hope it helps?

Expand|Select|Wrap|Line Numbers
  1. Call SetEnabledState(False)
The "Disable X" module code to save is:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, _
  5.     ByVal bRevert As Long) As Long
  6.  
  7. Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As _
  8.     Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
  9.  
  10. Const MF_GRAYED = &H1&
  11. Const MF_BYCOMMAND = &H0&
  12. Const SC_CLOSE = &HF060&
  13.  
  14. Public Function SetEnabledState(blnState As Boolean)
  15.     Call CloseButtonState(blnState)
  16.     'Call ExitMenuState(blnState)
  17. End Function
  18.  
  19. 'Disable the Menu Option
  20. 'Sub ExitMenuState(blnExitState As Boolean)
  21.    ' Application.CommandBars("File").Controls("Exit").Enabled = blnExitState
  22. 'End Sub
  23.  
  24. 'Disable the Close Button Option
  25. Sub CloseButtonState(boolClose As Boolean)
  26.     Dim hWnd As Long
  27.     Dim wFlags As Long
  28.     Dim hMenu As Long
  29.     Dim result As Long
  30.  
  31.     hWnd = Application.hWndAccessApp
  32.     hMenu = GetSystemMenu(hWnd, 0)
  33.     If Not boolClose Then
  34.         wFlags = MF_BYCOMMAND Or MF_GRAYED
  35.     Else
  36.         wFlags = MF_BYCOMMAND And Not MF_GRAYED
  37.     End If
  38.  
  39.     result = EnableMenuItem(hMenu, SC_CLOSE, wFlags)
  40. End Sub
Dec 29 '13 #4
NeoPa
32,556 Expert Mod 16PB
Neels, This is a dead thread (I'll close it now as possibly I should have earlier).

The linked thread has a perfectly adequate and appropriate solution that is a single line of code within an event procedure.
Dec 29 '13 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Nick250 | last post by:
I have a simple app that I created for our Real Estate office using Access 2000 and it is working fine except for on thing. I need to keep the close button hidden from the users. No problem...
3
by: Saurabh Sharma | last post by:
Hi How do i disable windows close button in forms in C# Regards Saurabh
2
by: RJN | last post by:
Hi I have a Popup window which has a Close button onclick of which I do some database operations. I want to ensure that , user doesn't close the window by clicking on X(Top right corner) and...
1
by: Kikita | last post by:
Hi! I am working on a Internet Exam form that requires the students to finish their tests before closing the window, if closed by accident, the points they get will be added to the ones they will...
0
by: danasegarane | last post by:
Dear All, I am using VBA to develop programms.How can i disable the word X button ? Dana
1
by: jamesdel | last post by:
Hi I know how to disable the close button of the main access window. But i am not able to disable the maximum button. Can anyone help me in this regard. It certainly needs API function calling...
2
by: Nageshwarrao | last post by:
Hi All, I have a window.open() popup.In which I placed an "Close" button.when I Click on that "Close" button it will pass some information to the Database and after that the window will...
6
by: phons | last post by:
i've created a CAB file using PDW of Visual Basic 6.0 and also installed it in the system.While running the software, when i click on the windows default "close" it does'nt terminate.
3
by: handumom | last post by:
is it possible to diseble the close button in pop up?what is the code in asp.net using vb
3
swarnalaxmi
by: swarnalaxmi | last post by:
In .net i created a datagridview to display a table... there i have to disable the close button. i searched in properties. i couldnot find. can you help? thanks in advance swarnalaxmi
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.