我已经解决了,请大家指正:
Private Sub Form_Load()
'让所有控件有效,初始化用户名和密码框
NameList.Enabled = True
PassTxt.Enabled = True
Study_Logon_command.Enabled = True
ExitCmd.Enabled = True
'NameList.ListIndex = -1
PassTxt.Value = ""
End Sub
Private Sub Study_Logon_command_Click()
If NameList.ListIndex = -1 Or PassTxt.Value = Null Then '判断是否选择了用户和是否输入了密码
MsgBox "请选择用户名并输入正确的密码!"
Else
If PassTxt.Value = DLookup("[考生密码]", "考生表", _
"[考生编号]=NameList.ListIndex+1") Then '判断输入的密码是否与选择用户的密码相同
MsgBox "ok"
Else: MsgBox "请选择用户名并输入正确的密码2"
End If
End If