hide the close "X" and "max." of Acces

bassy

Registered User.
Local time
Today, 18:04
Joined
Apr 17, 2003
Messages
13
Hello,

After starting my MS access database I would like to know how to hide the "X" and "max." of the Acces window .

I'm using Acces 2000 and VBA.

any idea for me will be great
 
For the Database Window, you can't - you can only hide the whole window.

On a form you can disable the Min, Max, and Close buttons.
 
thank you for the replay
 
'You can disable the 'X' that allows a user to close your db.

'This code will allow you to disable the 'X' to prevent the user from closing your application...

'Copy this function into a new module...
'Courtesy of Calvin Smith

Option Compare Database
Option Explicit

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 EnableDisableControlBoxX(bEnable As Boolean, Optional ByVal lhWndTarget As Long = 0) As Long
On Error GoTo Err_EnableDisableControlBoxX

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

EnableDisableControlBoxX = lReturnVal

Exit_EnableDisableControlBoxX:
Exit Function

Err_EnableDisableControlBoxX:
ErrorMsg Err.Number & " - " & Err.Description
Resume Exit_EnableDisableControlBoxX

End Function

'I test if the current user is me (the programmer). Use this in a forms OnOpen event or a transparent command button...
If CurrentUser <> "programmer" Then
EnableDisableControlBoxX (False) 'Disable the programs X (close) function
Exit Sub
Else
EnableDisableControlBoxX (True)
End If

'HTH
 
I've tried but still get error about the constant.The erro is :"the constants, the strings with fixed length, matrix you have declared and defined are not allowed as public members in object modules"
I don't understand what is wrong.
Below the code I use

Option Compare Database
Option Explicit

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 EnableDisableControlBoxX(bEnable As Boolean, Optional ByVal lhWndTarget As Long = 0) As Long
On Error GoTo Err_EnableDisableControlBoxX

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

EnableDisableControlBoxX = lReturnVal

Exit_EnableDisableControlBoxX:
Exit Function

Err_EnableDisableControlBoxX:
ErrorMsg Err.Number & " - " & Err.Description
Resume Exit_EnableDisableControlBoxX

End Function

Private Sub Form_Open(Cancel As Integer) ' the openeing of the mainmenu
DoCmd.MoveSize , , 7500, 5380
Dim i As Integer
Dim CurrentUser As String
CurrentUser = ""
For i = 1 To CommandBars.Count
CommandBars(i).Enabled = False
Next i
Application.SetOption "Show Status Bar", True

'I test if the current user is me (the programmer). Use this in a forms OnOpen event or a transparent command button...
If CurrentUser <> "programmer" Then
EnableDisableControlBoxX (False) 'Disable the programs X (close) function
Exit Sub
Else
EnableDisableControlBoxX (True)
End If
End Sub


but I still have the "X" after starting the database
Maybe I'm not using the function good..

any help will be grateful
 
The code ghudson gave you should go in a module and not on your form's code module.
 
how can you create a module code that isn't based on a form or on a report?

how can i link the the module to the event: "Onopen" of my form??

thanks for any reaction
 
Firstly, you make a module the same way you would a table, query, form, or macro by selecting New from the Database Window.

This is the code that goes in that module.

Code:
Option Compare Database 
Option Explicit 

    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 EnableDisableControlBoxX(bEnable As Boolean, Optional ByVal lhWndTarget As Long = 0) As Long 
On Error GoTo Err_EnableDisableControlBoxX 

    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 

EnableDisableControlBoxX = lReturnVal 

Exit_EnableDisableControlBoxX: 
Exit Function 

Err_EnableDisableControlBoxX: 
ErrorMsg Err.Number & " - " & Err.Description 
Resume Exit_EnableDisableControlBoxX 

End Function


And this is the code that goes on your form:

Code:
Private Sub Form_Open(Cancel As Integer) ' the openeing of the mainmenu 
DoCmd.MoveSize , , 7500, 5380 
Dim i As Integer 
Dim CurrentUser As String 
CurrentUser = "" 
For i = 1 To CommandBars.Count 
CommandBars(i).Enabled = False 
Next i 
Application.SetOption "Show Status Bar", True 

'I test if the current user is me (the programmer). Use this in a forms OnOpen event or a transparent command button... 
If CurrentUser <> "programmer" Then 
EnableDisableControlBoxX (False) 'Disable the programs X (close) function 
Exit Sub 
Else 
EnableDisableControlBoxX (True) 
End If 
End Sub

The latter procedure, on the form module, calls the function in your module so they are, in a way, linked - the word is 'public' meaning that anywhere else in your database now has access to it.
 
lot of thanks for all of you taking so much time replaying..
I have done exactly what's explained on the form but I get the following:

All my nemu is hidden(unable) I cannot navigate more trough the database and more, the close "X" is still able on the access window.

thanks for any replay
 

Users who are viewing this thread

Back
Top Bottom