Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit ms access 2000

Status
Not open for further replies.

xtreemnet

Programmer
Aug 9, 2003
88
0
0
NZ
Hi

Is there any event which gets fired when the user clicks the close button of ms access 2000. I would like the user to restrict to not to use but the exit button of my access application. Because a code needs to be executed when my application is closed.

Thanks,

 
No there isn't, to my knowledge, unless you provide it yourself. I'm using a method very close to what's described by mstrmage1768 in this faq faq702-1870.

Roy-Vidar
 
If you don't mind using a few API's, you can remove the Close button from the Access Window.

First in a module, declare the following APIs and public constants
Code:
Public Const WS_SYSMENU = &H80000
Public Const GWL_STYLE = (-16)

Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Now, in the startup form for the application, in the declarations section, drop in the following:
Code:
Option Explicit
Option Compare Database

Dim fLng_OrigWindWord      As Long
Next, again in the startup form for the application, in its Form_Load event, drop in the following code
Code:
Private Sub Form_Load()

   Dim lLng_HideAccessWord    As Long
   Dim lStr_TitleBarText      As String
   
   fLng_OrigWindWord = GetWindowLong(hWndAccessApp, GWL_STYLE)
   lLng_HideAccessWord = fLng_OrigWindWord And (Not WS_SYSMENU)
   SetWindowLong hWndAccessApp, GWL_STYLE, lLng_HideAccessWord
   
   lStr_TitleBarText = String(254, Chr(0))
   GetWindowText hWndAccessApp, lStr_TitleBarText, 253
   lStr_TitleBarText = Left(lStr_TitleBarText, InStr(lStr_TitleBarText, Chr(0)) - 1)
   SetWindowText hWndAccessApp, lStr_TitleBarText
The setting of the Title Bar text only serves to have the title bar repainted, thus removing the System Menu. If someone has a better way to repaint the Title Bar, I hope you post it.

Then in the Form Close event of that form which is used to shut down the application, drop in the following:
Code:
Private Sub Form_Unload(Cancel As Integer)

   SetWindowLong hWndAccessApp, GWL_STYLE, fLng_OrigWindWord

End Sub
I don't know why, but resetting the Text does not fully work here, but all you need to do is click on the Access Window Title Bar, and the System Menu reappears. Here again, a better way to force a TitleBar repaint would be nice.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks guys. Its working now. The solution in FAQ702-1870 is easier to use and it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top