Access - DESHABILITAR BOTON CERRAR ACCESS 2016

 
Vista:
sin imagen de perfil
Val: 29
Ha disminuido su posición en 6 puestos en Access (en relación al último mes)
Gráfica de Access

DESHABILITAR BOTON CERRAR ACCESS 2016

Publicado por Jose (17 intervenciones) el 18/03/2020 13:29:44
Hola programadores! Un saludo!

Estoy haciendo una aplicacion sencilla en acces, pero por el tipo de usuario, necesito que no puedan cerrar la aplicacion Access desde el boton cerrar y que lo hagan a traves de un boton de un formulario.

El problema es que por mas que intento y busco, no encuentro un codigo para deshabilitar el boton cerrar de la aplicacion, solo de formulario. Y menos para Access 2016.

Alguien puede ayudarme?

Muchas gracias desde ya.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 73
Ha aumentado su posición en 23 puestos en Access (en relación al último mes)
Gráfica de Access

DESHABILITAR BOTON CERRAR ACCESS 2016

Publicado por Marcos José (24 intervenciones) el 25/12/2020 22:22:15
En un módulo pon este código
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Public Sub AccessCloseButtonEnabled(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) FMS, Inc.
  ' Source  : Total Visual SourceBook
  ' Usage   : Permission granted to subscribers of the FMS Newsletter
 
  On Error Resume Next
 
  Const clngMF_ByCommand As Long = &H0&
  Const clngMF_Grayed As Long = &H1&
  Const clngSC_Close As Long = &HF060&
 
  Dim lngWindow As Long
  Dim lngMenu As Long
  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

Luego en el formulario de inicio colocas esto en el evento al cargar

1
2
3
Private Sub Form_Load()
Call AccessCloseButtonEnabled(False)
End Sub

y en el evento al cerrar

1
2
3
Private Sub Form_Close()
Call AccessCloseButtonEnabled(True)
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

DESHABILITAR BOTON CERRAR ACCESS 2016

Publicado por Jorge Rubio (11 intervenciones) el 02/07/2024 20:19:40
ya realice el copiado y tal como lo comentas pero tengo office 2016 a 64bit windows 11, el problema en el codigo aparece en GetSystemMenu alli se detiene y no permite continuar con el codigo me puedes ayudar? debo activar algun complemento o algo asi?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Eduardo Pérez Fernández

DESHABILITAR BOTON CERRAR <a href="#" class="google-anno" style="border: 0px !important; box

Publicado por Eduardo Pérez Fernández (362 intervenciones) el 04/07/2024 17:40:21
El código que te ofrecen solo corre en Access de 32 bits, pruebe con este para 32 y 64 bits

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Option Compare Database
Option Explicit
 
#If VBA7 Then
    Private Declare PtrSafe Function GetSystemMenu Lib "user32" _
                                           (ByVal hwnd As LongPtr, _
                                            ByVal bRevert 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 bRevert 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 Sub AccessCloseButtonEnabled(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 disables it
    ' Owner   : Copyright (c) FMS, Inc.
    ' Source  : Total Visual SourceBook
    ' Usage   : Permission granted to subscribers of the FMS Newsletter
 
    On Error Resume Next
 
    Const clngMF_ByCommand As Long = &H0&
    Const clngMF_Grayed As Long = &H1&
    Const clngSC_Close As Long = &HF060&
 
    Dim lngWindow As LongPtr
    Dim lngMenu As LongPtr
    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
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Eduardo Pérez Fernández

DESHABILITAR BOTON CERRAR ACCESS 2016

Publicado por Eduardo Pérez Fernández (362 intervenciones) el 04/07/2024 17:28:46
Le dejo esta opción con las API de Windows cuyo autor es Juan M Afán de Ribera

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
Option Compare Database
Option Explicit
 
' ActivateControlBox
' ActivateCloseBox
' ActivateMaximizeBox
' ActivateMinimizeBox
'
' Código escrito originalmente por Juan M Afán de Ribera.
' Estás autorizado a utilizarlo dentro de una aplicación
' siempre que esta nota de autor permanezca inalterada.
' En el caso de querer publicarlo en una página Web,
' por favor, contactar con el autor en
'
'     accessvbafaq@ya.com
'
' Este código se brinda por cortesía de
' Juan M. Afán de Ribera
'
Private Declare PtrSafe Function GetWindowLong Lib "user32" _
                                       Alias "GetWindowLongA" _
                                       (ByVal hwnd As Long, _
                                        ByVal nIndex As Long) As Long
 
Private Declare PtrSafe Function SetWindowLong Lib "user32" _
                                       Alias "SetWindowLongA" _
                                       (ByVal hwnd As Long, _
                                        ByVal nIndex As Long, _
                                        ByVal dwNewLong As Long) As Long
 
Private Declare PtrSafe Function GetSystemMenu _
                          Lib "user32" _
                              (ByVal hwnd As Long, _
                               ByVal bRevert As Long) As Long
 
Private Declare PtrSafe Function DrawMenuBar _
                          Lib "user32" _
                              (ByVal hwnd As Long) As Long
 
Private Declare PtrSafe Function DeleteMenu _
                          Lib "user32" _
                              (ByVal hMenu As Long, _
                               ByVal nPosition As Long, _
                               ByVal wFlags As Long) As Long
 
Private Const MF_BYCOMMAND = &H0&
Private Const SC_CLOSE = &HF060
 
Private Const WS_SYSMENU = &H80000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
 
Private Const GWL_STYLE = (-16)
Function ap_DesactivaShift()
' Esta función desactiva la tecla SHIFT permitiendo se ejecute la macro
' Autoexec y demás propiedades de inicilaización
 
    On Error GoTo errDisableShift
 
    Dim db As Database
    Dim prop As Property
    Const conPropNotFound = 3270
 
    Set db = CurrentDb()
 
    'La siguiente linea desactiva la tecla Shift en el arranque
 
 
 
    db.Properties("AllowByPassKey") = False
 
    'function successful
    Exit Function
 
errDisableShift:
 
    'Esta primera parte de la subrutina de error crea la propiead "AllowByPassKey
    'si esta no existe
 
    If Err = conPropNotFound Then
        Set prop = db.CreateProperty("AllowByPassKey", _
                                     dbBoolean, False)
        db.Properties.Append prop
        Resume Next
    Else
        MsgBox "Función 'ap_DisableShift' no se completó satisfactoriamente."
        Exit Function
    End If
 
End Function
Function EnableShift()
'Esta función habilita la tecla SHIFT al inicio. Esta acción provoca
'la macro Autoexec y las propiedades de inicio se omitirán
'si el usuario mantiene presionada la tecla MAYÚS cuando abre la base de datos.
 
On Error GoTo errEnableShift
 
    Dim db As DAO.Database
    Dim prop As DAO.Property
    Const conPropNotFound = 3270
 
    Set db = CurrentDb()
 
    'La siguiente línea de código activa la tecla SHIFT al inicio.
    db.Properties("AllowByPassKey") = True
 
    'function successful
    Debug.Print "Enabled Shift Key - Successful"
    GoTo ExitHere
 
errEnableShift:
 
    'La primera parte de esta rutina de error crea el "AllowByPassKey
    'propiedad si no existe.
 
    If Err = conPropNotFound Then
        Set prop = db.CreateProperty("AllowByPassKey", _
        dbBoolean, True)
        db.Properties.Append prop
        Resume Next
        Else
            MsgBox "Function 'ap_DisableShift' did not complete successfully."
            GoTo ExitHere
    End If
 
ExitHere:
    Set prop = Nothing
    Set db = Nothing
    Exit Function
 
End Function
'---------------------------------------------------------
'
' ActivateControlBox
'
' Activa/desactiva el cuadro de control de la barra de
' título de la ventana principal de Access (junto con el
' icono y el menú completo)
'
Function ActivateControlBox(Enable As Boolean)
    Dim CurStyle As Long
    Dim hwnd As Long
 
    hwnd = Access.hWndAccessApp
 
    CurStyle = GetWindowLong(hwnd, GWL_STYLE)
    If Enable Then
        If Not (CurStyle And WS_SYSMENU) Then
            CurStyle = CurStyle Or WS_SYSMENU
        End If
    Else
        If (CurStyle And WS_SYSMENU) = WS_SYSMENU Then
            CurStyle = CurStyle - WS_SYSMENU
        End If
    End If
    Call SetWindowLong(hwnd, GWL_STYLE, CurStyle)
    Call DrawMenuBar(hwnd)
 
End Function
'---------------------------------------------------------
 
'---------------------------------------------------------
'
' ActivateCloseBox
'
' Activa/desactiva el botón cerrar [X] de la barra de
' título de la ventana principal de Access (junto con la
' correspondiente opción en el menú)
'
Function ActivateCloseBox(Enable As Boolean)
    Dim hMenu As Long
    Dim hwnd As Long
 
    hwnd = Access.hWndAccessApp
 
    If Enable Then
        Call GetSystemMenu(hwnd, True)
    Else
        hMenu = GetSystemMenu(hwnd, False)
        If hMenu Then
            Call DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
        End If
    End If
    Call DrawMenuBar(hwnd)
 
End Function
'---------------------------------------------------------
 
'---------------------------------------------------------
'
' ActivateMaximizeBox
'
' Activa/desactiva el botón maximizar [ ] de la barra de
' título de la ventana principal de Access (junto con la
' correspondiente opción en el menú)
'
Function ActivateMaximizeBox(Enable As Boolean)
    Dim CurStyle As Long
    Dim hwnd As Long
 
    hwnd = Access.hWndAccessApp
 
    CurStyle = GetWindowLong(hwnd, GWL_STYLE)
    If Enable Then
        If Not (CurStyle And WS_MAXIMIZEBOX) Then
            CurStyle = CurStyle Or WS_MAXIMIZEBOX
        End If
    Else
        If (CurStyle And WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX Then
            CurStyle = CurStyle - WS_MAXIMIZEBOX
        End If
    End If
    Call SetWindowLong(hwnd, GWL_STYLE, CurStyle)
    Call DrawMenuBar(hwnd)
 
End Function
'---------------------------------------------------------
 
'---------------------------------------------------------
'
' ActivateMinimizeBox
'
' Activa/desactiva el botón minimizar [_] de la barra de
' título de la ventana principal de Access (junto con la
' correspondiente opción en el menú)
'
Function ActivateMinimizeBox(Enable As Boolean)
    Dim CurStyle As Long
    Dim hwnd As Long
 
    hwnd = Access.hWndAccessApp
 
    CurStyle = GetWindowLong(hwnd, GWL_STYLE)
    If Enable Then
        If Not (CurStyle And WS_MINIMIZEBOX) Then
            CurStyle = CurStyle Or WS_MINIMIZEBOX
        End If
    Else
        If (CurStyle And WS_MINIMIZEBOX) = WS_MINIMIZEBOX Then
            CurStyle = CurStyle - WS_MINIMIZEBOX
        End If
    End If
    Call SetWindowLong(hwnd, GWL_STYLE, CurStyle)
    Call DrawMenuBar(hwnd)
 
End Function
'---------------------------------------------------------
' StartUpProperties
'
' Código escrito originalmente por Juan M Afán de Ribera.
' Estás autorizado a utilizarlo dentro de una aplicación
' siempre que esta nota de autor permanezca inalterada.
' En el caso de querer publicarlo en una página Web,
' por favor, contactar con el autor en
'
'     accessvbafaq@ya.com
'
' Este código se brinda por cortesía de
' Juan M. Afán de Ribera
'
Function StartUpProperties( _
         PrpName As String, _
         PrpValue As Variant, _
         Optional DBPath As String) As Long
 
    Dim db As Object    'DAO.Database
    Dim prp As Object    'DAO.Property
    Dim IconPath As Long
 
    Err.Clear
    On Error Resume Next
    ' si la propiedad a cambiar es AppIcon
    ' comprobamos que la ruta del icono sea válida
    If PrpName = "AppIcon" Then
        IconPath = Len(Dir(PrpValue))
        If IconPath = 0 Then
            'Nombre o número de archivo incorrecto
            StartUpProperties = 52
            Exit Function
        End If
    End If
    On Error GoTo 0
 
    On Error GoTo err_StartUpProperties
 
    If DBPath = "" Then
        Set db = CurrentDb
    Else
        Set db = DBEngine.OpenDatabase(DBPath)
    End If
    db.Properties(PrpName).Value = PrpValue
    db.Properties.Refresh
 
    Err.Clear
    On Error Resume Next
    ' comprobamos que la ruta del icono asociado a la base de datos
    ' (si es que existe), sea válida. Si no fuera así provocaría que
    ' la propiedad que se ha cambiado/creado no se refrescara.
    IconPath = Len(Dir(db.Properties("AppIcon")))
    If IconPath = 0 Then
        ' borramos la propiedad
        db.Properties.Delete "AppIcon"
    End If
    On Error GoTo 0
 
    Application.RefreshTitleBar
    StartUpProperties = -1
 
exit_StartUpProperties:
 
    Set db = Nothing
    Exit Function
 
err_StartUpProperties:
 
    If Err.Number = 3270 Then    'la propiedad no existe
        Select Case PrpName
            ' Se crea una propiedad tipo booleano
        Case "StartUpShowDBWindow", _
             "StartupShowStatusBar", _
             "AllowShortcutMenus", _
             "AllowFullMenus", _
             "AllowBuiltInToolbars", _
             "AllowToolbarChanges", _
             "AllowSpecialKeys", _
             "AllowBypassKey", _
             "AllowBreakIntoCode", _
             "HijriCalendar", _
             "UseAppIconForFrmRpt"
            Set prp = db.CreateProperty _
                      (PrpName, DB_BOOLEAN, PrpValue)
            db.Properties.Append prp
            Set prp = Nothing
            ' Se crea una propiedad tipo texto
        Case "AppTitle", _
             "StartUpForm", _
             "AppIcon", _
             "StartUpMenuBar", _
             "StartUpShortcutMenuBar"
            Set prp = db.CreateProperty _
                      (PrpName, DB_TEXT, PrpValue)
            db.Properties.Append prp
            Set prp = Nothing
 
        Case Else
            ' la propiedad no existe
            StartUpProperties = 3270
            Resume exit_StartUpProperties
        End Select
 
        Resume Next
        ' error inesperado
    Else
        MsgBox "Error: " & Err.Number & vbCrLf & _
               Err.Description
        StartUpProperties = Err.Number
        Resume exit_StartUpProperties
    End If
 
End Function

En el caso de su pregunta puede crear un macro y llamar la función

ActivateCloseBox(True)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar