Private Sub CmdLogInCancel_Click()
Unload Me
End Sub
Private Sub CmdLogInOK_Click()
On Error GoTo Kiet
'==========================================================================
'Kiem tra NewName va NewCode - Khi nhap thieu Name hoac code se co thong bao loi:
'==========================================================================
If (IsNull(TxtLogInNewUserName) Or TxtLogInNewUserName = "") _
And (TxtLogInNewUserCode <> "" And IsNull(TxtLogInNewUserCode) = False) Then
a = MsgBox("Name must be completed!", vbCritical, "Warning!")
TxtLogInNewUserName.SetFocus
Exit Sub
ElseIf (IsNull(TxtLogInNewUserCode) Or TxtLogInNewUserCode = "") _
And (TxtLogInNewUserName <> "" And IsNull(TxtLogInNewUserName) = False) Then
a = MsgBox("Code must be completed!", vbCritical, "Warning!")
TxtLogInNewUserCode.SetFocus
Exit Sub
End If
'***********************************************************************************
'==========================================================================
'Kiem tra NewName va NewCode co trung voi du lieu da co hay khong, neu trung thi coi nhu la lua chon mot user trong list
'Name co the trung nhung Code Thi khong
'==========================================================================
If (IsNull(TxtLogInNewUserName) = False And TxtLogInNewUserName <> "") _
And (TxtLogInNewUserCode <> "" And IsNull(TxtLogInNewUserCode) = False) Then
Dim MyCheck As Boolean, Zi As Long
MyCheck = False
'----------------------------------------------------------------------------------------------------------------------------------------
Dim MyListRow As Integer
MyListRow = LstListUser.ListCount
For Zi = 0 To MyListRow - 1
If LstListUser.List(Zi, 0) = TxtLogInNewUserName.Value And LstListUser.List(Zi, 1) = TxtLogInNewUserCode.Value Then
MyCheck = True
Range("CurUserName") = TxtLogInNewUserName
Range("CurUserCode") = TxtLogInNewUserCode
Unload Me
'===============================================================
'[B]THÊM CHỖ NÀY:[/B]
ElseIf LstListUser.List(Zi, 0) <> TxtLogInNewUserName.Value And LstListUser.List(Zi, 1) = TxtLogInNewUserCode.Value Then _
a = MsgBox("New UserCode has already exist! Please choose another UserCode or change the UserName!", vbCritical, "Warning")
Exit Sub
'===============================================================
End If
Next Zi
End If
'----------------------------------------------------------------------------------------------------------------------------------------
Dim TargetRow As Integer
If MyCheck = False And TxtLogInNewUserCode <> "" And IsNull(TxtLogInNewUserCode) = False And TxtLogInNewUserName <> "" _
And IsNull(TxtLogInNewUserCode) = False And IsNull(TxtLogInNewUserName) = False Then
a = MsgBox("New UserName and UserCode will be created! Do you want to do this!", vbYesNo, "Processing......")
If a = vbYes Then
TargetRow = Sheets("Sheet1").Range("B65000").End(xlUp).Row + 1
Range("CurUserName") = TxtLogInNewUserName
Range("CurUserCode") = TxtLogInNewUserCode
Sheets("Sheet1").Cells(TargetRow, 2) = TxtLogInNewUserName
Sheets("Sheet1").Cells(TargetRow, 3) = TxtLogInNewUserCode
Unload Me
Else
Exit Sub
End If
End If
'***********************************************************************************
'==========================================================================
'Kiem tra NewName va NewCode - Neu NewName va NewCode deu rong (Null) thi lay gia tri trong listbox dua vao:
'==========================================================================
If (TxtLogInNewUserCode = "" Or IsNull(TxtLogInNewUserCode)) And (TxtLogInNewUserName = "" Or IsNull(TxtLogInNewUserName)) Then
Range("CurUserName") = LstListUser.Value
Range("CurUserCode") = LstListUser.Column(1)
Unload Me
Else
Exit Sub
End If
'==========================================================================
Exit_K:
Exit Sub
Kiet:
MsgBox Err.Number & Chr(13) & Err.Description & Chr(13) & "If NewName and NewCode is Blank, you must select a UserName in listbox to Log In", vbCritical, "Warning!"
Resume Exit_K
End Sub