Passwrod to close Database

mike wild

Registered User.
Local time
Today, 22:27
Joined
Feb 16, 2003
Messages
69
If somebody tries to close the program or the database, I am looking at setting up a password system.
I know that if the password is unsucsessfull then:

docmd.resume
What i have so far:

Dim pass As String
Dim db As Database
Set db = CurrentDb()
Dim docname As String
If Forms.Unload.pass = "acc" Then
DoCmd.Quit
Exit Sub
Else
If Forms.Unload.pass = "a" Then
DoCmd.Close acForm, "unload", acSaveNo
'DoCmd.Restore

'DoCmd.Close acForm, "mainscreen", acSaveNo
Else
DoCmd.Close
docname = "mainscreen"
DoCmd.OpenForm acForm, docname
DoCmd.Restore
End If
End If


i've been playing about with it.
But i need it to work when someone has presses the program close button.

I have the above code to trigger on the mainscreen "unload" event.
 
Why would you want to have a password on exit? Anyways,
Macro to disable X button:
to call: EnableDisableControlBox (False)
Option Compare Database
Option Explicit


'**********************************************************

'We need the following API declarations first
Public Declare Function apiEnableMenuItem Lib "user32" Alias "EnableMenuItem" (ByVal hMenu As Long, ByVal wIDEnableMenuItem As Long, ByVal wEnable As Long) As Long
Public Declare Function apiGetSystemMenu Lib "user32" Alias "GetSystemMenu" (ByVal hWnd As Long, ByVal flag As Long) As Long

Public Function EnableDisableControlBox(bEnable As Boolean, Optional ByVal lhWndTarget As Long = 0) As Long
On Error GoTo ErrorHandling_Err

' ----------------------------------------------------------------------
' Purpose: Example of how to disable or enable the control box of
' a form, report, or the Access parent window.
'
' Accepts: bEnable, which determines whether to disable or enable
' the control box
'
' Also accepts lhWndTarget (which is optional), if you want
' to use a window handle other than the Access parent window.
'
' Returns: N/A
'
' Example usage: lRetVal = EnableDisableControlBox(True) to enable -OR-
' lRetVal = EnableDisableControlBox(False) to disable
'
' NOTE: If no hWnd is passed in for a specific form, then the code
' assumes you want to enable/disable the Access parent window
' ----------------------------------------------------------------------

Const MF_BYCOMMAND = &H0&
Const MF_DISABLED = &H2&
Const MF_ENABLED = &H0&
Const MF_GRAYED = &H1&
Const SC_CLOSE = &HF060&

Dim lhWndMenu As Long
Dim lReturnVal As Long
Dim lAction As Long

lhWndMenu = apiGetSystemMenu(IIf(lhWndTarget = 0, Application.hWndAccessApp, lhWndTarget), False)

If lhWndMenu <> 0 Then
If bEnable Then
lAction = MF_BYCOMMAND Or MF_ENABLED
Else
lAction = MF_BYCOMMAND Or MF_DISABLED Or MF_GRAYED
End If
lReturnVal = apiEnableMenuItem(lhWndMenu, SC_CLOSE, lAction)
End If

EnableDisableControlBox = lReturnVal

ErrorHandling_Err:
If Err Then
'Trap your error(s) here, if any!
End If

End Function
END
 
Thank so much.

Thats so much better
 
what is the correct code of minimize

i have
WS_MAXIMIZEBOX = &H10000

but does not work
 
I'm trying to also gray our the parent window (program) minimize button
 
Oh i see what you mean, i ll have to look into that, i m working on a project at the moment but i ll gt back to you, in the meantime maybe someone else can point out the code?
 

Users who are viewing this thread

Back
Top Bottom