Convidado 26/4/2011, 13:12
Retirei este exemplo do site de suporte da Kartoffell
1. Crie um módulo classe (não confunda com módulo padrão) de nome "CloseCommand", contendo o código abaixo:
Option Compare Database
Option Explicit
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
Private Declare Function GetMenuItemInfo Lib "user32" Alias _
"GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As _
Long, lpMenuItemInfo As MENUITEMINFO) As Long
Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type
Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&
Public Property Get Enabled() As Boolean
Dim hWnd As Long
Dim hMenu As Long
Dim result As Long
Dim MI As MENUITEMINFO
MI.cbSize = Len(MI)
MI.dwTypeData = String(80, 0)
MI.cch = Len(MI.dwTypeData)
MI.fMask = MF_GRAYED
MI.wID = SC_CLOSE
hWnd = Application.hWndAccessApp
hMenu = GetSystemMenu(hWnd, 0)
result = GetMenuItemInfo(hMenu, MI.wID, 0, MI)
Enabled = (MI.fState And MF_GRAYED) = 0
End Property
Public Property Let Enabled(boolClose As Boolean)
Dim hWnd As Long
Dim wFlags As Long
Dim hMenu As Long
Dim result As Long
hWnd = Application.hWndAccessApp
hMenu = GetSystemMenu(hWnd, 0)
If Not boolClose Then
wFlags = MF_BYCOMMAND Or MF_GRAYED
Else
wFlags = MF_BYCOMMAND And Not MF_GRAYED
End If
result = EnableMenuItem(hMenu, SC_CLOSE, wFlags)
End Property
2. Crie agora um módulo padrão, de nome "basTeste", contendo o código abaixo:
Function InitApplication()
Dim c As CloseCommand
Set c = New CloseCommand
'Disable Close menu.
c.Enabled = False
End Function
3. Clique no menu Depurar e compile o banco de dados. Depois, volte à janela principal do Access e salve o banco (menu Arquivo - Salvar).
4. Crie uma macro chamada Autoexec com as seguintes ações e argumentos:
Ação
-------
ExecutarCódigo
Argumentos da ação
-------------------------------
Nome da função: InitApplication()
Mas a Macro nao reconhece o nome da funcao..
no codigo
Function InitApplication()
Dim c As CloseCommand ---- (AQUI DA O TIPO DEFINIDO POELO USUARIO NAO FOI DEFINIDO
Set c = New CloseCommand
'Disable Close menu.
c.Enabled = False
End Function
Podem me Ajudar?