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 Function决定使用其布尔参数禁用或启用关闭按钮。)如何禁用MS Access中对话框的关闭按钮?
哪个对话框?顺便说一句,你知道这条线'hwnd = Application.hWndAccessApp'吗? –
我的意思是getPermission函数出现的对话框。 (DoCmd.OpenForm“Startup”,acNormal,,,,acDialog) –
实际上,我不太清楚hwnd = Application.hWndAccessApp的功能。 @SiddharthRout –