Acces Runtime still showing the control "x" on the right top

Sepp1945

Member
Local time
Tomorrow, 05:23
Joined
Feb 12, 2023
Messages
33
i have removed the tool bar with
****
DoCmd.ShowToolbar "Ribbon", acToolbarNo" and 'Me.Caption = " "
****
but it still shows
1676715721268.png


can i remove this?
Thank you ver much

Sepp
 
copy this in New Module:
Code:
#If VBA7 Then
    Private Declare PtrSafe Function GetSystemMenu Lib "USER32" (ByVal hWnd As LongPtr, ByVal wRevert As Long) As LongPtr
    Private Declare PtrSafe Function EnableMenuItem Lib "USER32" (ByVal hMenu As LongPtr, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
#Else
    Private Declare Function GetSystemMenu Lib "USER32" (ByVal hWnd As Long, ByVal wRevert As Long) As Long
    Private Declare Function EnableMenuItem Lib "USER32" (ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
#End If


Public Function EnableAccessCloseButton(pfEnabled As Boolean)
 
    ' Comments: Control the Access close button.
    '           Disabling it forces the user to exit within the application
    ' Params  : pfEnabled       TRUE enables the close button, FALSE disabled it
    ' Owner   : Copyright (c) 2008-2011 from FMS, Inc.
    ' Source  : Total Visual SourceBook
    ' Usage   : Permission granted to subscribers of the FMS Newsletter
    ' Reference http://www.fmsinc.com/microsoftaccess/startup/preventclose.asp
 
  On Error Resume Next

  Const clngMF_ByCommand As Long = &H0&
  Const clngMF_Grayed As Long = &H1&
  Const clngSC_Close As Long = &HF060&

#If VBA7 Then
  Dim lngWindow As LongPtr
  Dim lngMenu As LongPtr
#Else
  Dim lngWindow As Long
  Dim lngMenu As Long
#End If
  Dim lngFlags As Long

  lngWindow = Application.hWndAccessApp
  lngMenu = GetSystemMenu(lngWindow, 0)
  If pfEnabled Then
    lngFlags = clngMF_ByCommand And Not clngMF_Grayed
  Else
    lngFlags = clngMF_ByCommand Or clngMF_Grayed
  End If
  Call EnableMenuItem(lngMenu, clngSC_Close, lngFlags)
End Sub

then from Autoexec macro:

RunCode
=EnableAccessCloseButton(False)

note that when you close your app, be sure to re-instate it:

Call EnableAccessCloseButton(True)
 
here is a sample db.
when the db opens, you enable all macros (this will make Autoexec macro to run).
test by clicking the "X" button of Access.

there is another macro that will enable it back.
double click EnableCloseButton macro to enable closing the app.
test it again by clicking the "X" button.

note for this to work you must have some form or Switchboard that you can
put the code to Enable back the button.
 

Attachments

then before Closing the App (Exit button), you Enable the button:

Call EnableAccessCloseButton(True)
Application.Quit
 
@Sepp1945
If you don't need the title bar at all, then the close button is easy to remove. There are at least two possible approaches
1. Hide the Access application interface completely
2. Remove the title bar buttons

Both of these are explained in my article
 
@Sepp1945
If you don't need the title bar at all, then the close button is easy to remove. There are at least two possible approaches
1. Hide the Access application interface completely
2. Remove the title bar buttons

Both of these are explained in my article
I have added the following code (from your sample) into the load event
****************************

On Error GoTo Err_Handler

Me.cmdRestore.Caption = "Maximize Form"
cmdRestore_Click
Me.cmdTaskbar.Caption = "Hide Taskbar"
cmdTaskbar_Click

UISetRoundRect Me, 0, False 'CR v3.51

Me.cmdRestore.SetFocus
Me.cmdFillScreen.Enabled = False

Exit_Handler:
Exit Sub

Err_Handler:
strProc = "cmdFillScreen_Click"
MsgBox "Error " & Err.Number & " in " & strProc & " procedure : " & Err.Description
Resume Exit_Handler

***************
but it returns an error " cmdRestore. not found

What am i missing


Thank you

Sepp
 
That code refers to command buttons from the main form and to a function UISetRoundRect which is in a separate module.
Why did you select that button code rather than look at my own Form_Load event code?

You can't just randomly copy code and expect it to work. You need to study the code to make sure you understand which parts to use

Perhaps it would be easier for you to start with the simpler example RemoveTitleBarButtons elsewhere in that article
 
That code refers to command buttons from the main form and to a function UISetRoundRect which is in a separate module.
Why did you select that button code rather than look at my own Form_Load event code?

You can't just randomly copy code and expect it to work. You need to study the code to make sure you understand which parts to use

Perhaps it would be easier for you to start with the simpler example RemoveTitleBarButtons elsewhere in that article
Sorry,my mistake, will research again,

Many thanks
Sepp
 
Sorry,my mistake, will research again,

Many thanks
Sepp
I used now your code from the actual selection,
*********************************************************
Private Sub cmdAppWindow_Click()

On Error GoTo Err_Handler

If Me.cmdAppWindow.Caption = "Show Application Window" Then
'can't do this if form maximized & fills screen
DoCmd.Restore
Me.cmdRestore.Caption = "Maximize Form"

' SetAccessWindow (SW_SHOWMAXIMIZED)
SetAccessWindow (SW_SHOW) 'v3.43
HideRibbon 'v3.43
'blnShowWindow = True
Me.cmdAppWindow.Caption = "Hide Application Window"
Me.cmdHideIcon.Caption = "Hide Taskbar Icon"
Me.cmdHide.Enabled = True
DoEvents
Else
blnContinue = True 'CR v362 - added to fix issue where user clicks Close Window on taskbar icon

'close & reopen form
Application.Echo False
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "frmStart"
' SetAccessWindow (SW_SHOWMINIMIZED)
Application.Echo True

blnContinue = False 'CR v362
blnShowWindow = False
End If

Exit_Handler:
Exit Sub

Err_Handler:
strProc = "cmdAppWindow_Click"
MsgBox "Error " & Err.Number & " in " & strProc & " procedure : " & Err.description
Resume Exit_Handler

End Sub

***************************************************
this is what i get

1676724878849.png
 
My example app is designed to show many ways of controlling the application interface.
It uses lots of APIs and module code.
You cannot expect that any part of the main form code will work if just copied into another database
The same comments apply as before. Copying my code out of context will not work.

You almost certainly don't have any of those command buttons and probably haven't got a form frmStart.
Do you have any idea what these lines do?
Code:
SetAccessWindow (SW_SHOW)
HideRibbon 'v3.43

Have you looked at the RemoveTitleBarButtons example yet? If not, please do so

Also when posting code, please use the code button # on the toolbar to preserve code indentation
 

Users who are viewing this thread

Back
Top Bottom