Lỗi mã code trong form login
quanghoa > 06-11-14, 12:31 AM
Mình đã tạo xong form login chạy ổn rồi, khi chưa nhập code cho form login thì chuyển qua MDE bình thường, tuy nhiên sau khi nhập code cho form login thì không thể chuyển qua file MDE được. Đoạn code của mình đây:
Option Compare Database
Private intLogonAttempts As Integer
Private Sub cboEmployee_NotInList(NewData As String, Response As Integer)
MsgBox "Ban phai nhap dung 'User name' cua ban.", vbInformation, Me.Caption
Response = acDataErrContinue
End Sub
Private Sub cmdCancel_Click()
On Error GoTo Err_cmdCancel_Click
DoCmd.Quit
Exit_cmdCancel_Click:
Exit Sub
Err_cmdCancel_Click:
MsgBox Err.Description
Resume Exit_cmdCancel_Click
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.cboEmployee.SetFocus
End Sub
Private Sub cboEmployee_AfterUpdate()
txtstrAccess = DLookup("strAccess", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)
Me!txtUserName = Me!cboEmployee.Column(2)
Me.txtPassword.SetFocus
End Sub
Private Sub cmdLogin_Click()
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "Ban phai chon 'User Name' cua ban.", vbCritical, "User name"
Me.cboEmployee.SetFocus
Exit Sub
End If
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "Ban phai nhap mat khau cua ban vao o 'Password'.", vbCritical, "Nhap mat khau"
Me.txtPassword.SetFocus
Exit Sub
End If
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
lngMyEmpID = Me.cboEmployee.Value
MsgBox "Ban da dang nhap thanh cong...", vbInformation, "Dang nhap..."
DoCmd.OpenForm "frmMain"
Me.Visible = False
Else
MsgBox "Mat khau khong dung. Vui long nhap lai.", vbExclamation, "Sai mat khau!"
Me.txtPassword.SetFocus
End If
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 2 Then
MsgBox "Mat khau khong dung, chuong trinh se thoat. Vui long lien he voi Admin.", vbCritical, "Mat khau!"
Application.Quit
End If
End Sub
Không biết có lỗi gì trong đó các ban nghiên cứu dùm nhé. Thanks