如何在MS Access中禁用对话框的关闭按钮?

时间:2013-12-16 01:14:34

标签: vba ms-access

Option Compare Database    

Dim pUser As String

Private Sub signinCmd_Click()    
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb

Dim idEntered As String
Dim pwEntered As String

idEntered = Me.idBox & ""
pwEntered = Me.pwBox & ""

pUser = idEntered

Set rst = db.OpenRecordset ("SELECT * " & vbCrLf & _
    "From userInfo " & vbCrLf & "WHERE [ID] = '" Me.idBox & "'")

    If pwEntered = rst.Fields("Password") & "" Then
        Call getPermission(idEntered)
    Else
        MsgBox "You typed the wrong password. Try Again.", vbExclamation, "Security"
    End If
End Sub





Sub getPermission(pStr As String)
  Select Case pStr
    Case "Guest"
        SetEnabledState(False)
        DoCmd.LockNavigationPane(True)
        DoCmd.Close
        DoCmd.OpenForm "Startup", acNormal, , , , acDialog
    Case "Manager"
        DoCmd.LockNavigationPane(True)
        DoCmd.Close
        DoCmd.OpenForm "Startup", acNormal, , , , acDialog
    Case "Administrator"
        DoCmd.Close
        DoCmd.OpenForm "Startup", acNormal, , , , acDialog
 End Select
End Sub




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

Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&

Public Function SetEnabledState(bInState As Boolean)
    Call CloseButtonState(bInState)
    Call ExitMenuState(bInState)
End Function

Sub ExitMenuState(bInExitState As Boolean)
    Application.CommandBars("File").Controls("Exit").Enabled = bInExitState
End Sub

Sub CloseButtonState(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 Sub

我试图在“guest”登录时仅禁用对话框的关闭按钮,但是当我运行此代码时,不是该框的关闭按钮,而是禁用了MS Access的关闭按钮。如何在代码中解决这个问题? (SetEnabledState函数决定使用其布尔参数禁用或启用关闭按钮。)

0 个答案:

没有答案