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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

prevent a user from closing an access runtime app. 2

Status
Not open for further replies.

CPUburn

Programmer
Jan 18, 2001
146
BE
hen a subform within a certain form in the application is locked the user should not be able to close the application. At first glance the solution might seem obvious: in the unload event of the main form there's a statement which checks whether the subform is locked or not,
if it is the unload event is canceled. While closing access, the unload event of the form is also triggered, so there's no problem. The problem arises while starting access with a /runtime switch, in that case FIRST the "application.quit" is triggered, and after all windows have been closed there 's my message that warns the user the form cannot be closed at this stage.
Is there anyone who can offer me a solution to this ??
Thx
 
Removing the applications caption bar may help. I needed to do the same thing, but keeping a form open that locks the database was not a good solution for me. I found a function in Access 97 Developer's Handbook that removes the application's caption bar, thus removing the close button at the top right corner of the screen. It works great!!!! All you need to do is call the function when your application starts up.

Call the function:
Call adhRemoveWindowCaptionBar(Application.hWndAccessApp)

Here's the function:
Declare Function adh_apiGetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long

Declare Function adh_apiSetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Sub adhRemoveWindowCaptionBar(ByVal hwnd As Long)

' Remove a window's caption bar, given its hWnd.

' From Access 97 Developer's Handbook
' by Litwin, Getz, and Gilbert (Sybex)
' Copyright 1997. All rights reserved.

' In:
' hwnd: Window handle for the window whose caption you
' want to remove

Dim lngOldStyle As Long
Dim lngNewStyle As Long

' Get the current window style of the form.
lngOldStyle = adh_apiGetWindowLong(hwnd, adhcGWL_STYLE)

' Turn off the bit that enables the caption.
lngNewStyle = lngOldStyle And Not adhcWS_CAPTION

' Set the new window style.
lngOldStyle = adh_apiSetWindowLong(hwnd, adhcGWL_STYLE, lngNewStyle)

End Sub
 
thanks !

problem = solved with a few adjustments to acc 2000

the kid
 
If the only thing you want to do is prevent the user from closing a form the normal way then there are lots of options besides hiding the whole caption bar.

Simplest: Set the 'Close' property of the form to false is design view.
Slickest: Set the 'Close' property of the form during runtime depending on who has logged on.
Disable only the 'Close' button using Windows calls:

Option Compare Database
Option Explicit

Declare Function GetSystemMenu Lib "user32" (ByVal Hwnd As Integer, _
ByVal bRevert As Integer) As Integer

Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, _
ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer

Global Const MF_BYPOSITION = &H400

'Then open your form and enter the following code in the form's Load _
event:

Public Sub Hide_CloseButton(Hwnd As Integer)
On Error GoTo HandleErr

Dim SystemMenu As Integer, Res As Integer
SystemMenu = GetSystemMenu(Hwnd, 0)
Res = RemoveMenu(SystemMenu%, 6, MF_BYPOSITION)

ExitProc:
Exit Sub

HandleErr:
MsgBox Err.Number & ": " & Err.Description
GoTo ExitProc

End Sub

Steve King
 
hi scking,

thx ..
the original problem was however to prevent a user from closing the access application, not a form withing the application, but by applying the api-call to the application window it must work.

the kid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top