Private Sub login_Click()
Dim fpass As String, fusername As String, flevel As String
fusername = Nz(DlookUp("[UserName]","UserLogin","[UserName]='" & Me.UserBox & "'"))
If fusername = "" Then
MsgBox "ชื่อผู้ใช้ไม่ถูกต้อง", vbCritical, "ไม่พบรายชื่อผู้ใช้งาน"
Me.Undo
Me.UserBox.SetFocus
Else
fpass = Nz(DlookUp("[Password]","UserLogin","[UserName]='" & Me.UserBox & "'"))
If fpass = Me.PassBox Then
flevel = DlookUp("[Level]","UserLogin","[UserName]='" & Me.UserBox & "'")
SetUserLevel flevel
DoCmd.OpenForm "Main Form", acNormal
Else
MsgBox "รหัสผ่านไม่ถูกต้อง", vbCritical, "พบข้อผิดพลาด"
Me.Undo
Me.UserBox.SetFocus
End If
End If
End Sub