tamangspace
Registered User.
- Local time
- Today, 03:44
- Joined
- Jul 15, 2012
- Messages
- 37
Hello guys,
I created a login form using the below code. I got the code in this FORUM. thanks for you all. It works perfectly. I don't know how to create codes in vb. I started to read through this forum and learning a bit.
Now I want to create another login form. It would work for password change if any user forgets his password. I used the code to verify 'secret word' and open the 'password change form'. but it is not working. The MsgBox shows "Invalid Secret Word" even if secret word is correct. I paste the code below.
Option Compare Database
'********************************
'********************************
'*** ***
'*** Created by Tamangspace ***
'*** ***
'********************************
'********************************
Private intLogAttempt As Integer
Private Sub cboUser_GotFocus()
cboUser.Dropdown
End Sub
Private Sub cmdExit_Click()
MsgBox "Are you really want to exit this application?"
If response = vbYes Then
Application.Quit
End If
End Sub
Private Sub cmdLogin_Click()
Call Login
End Sub
Private Sub cmdLogin_Enter()
Call Login
End Sub
Public Sub Form_Load()
txtFocus.SetFocus 'txtFocus is a textbox control with height, width and positions set to zero
End Sub
Public Sub Login()
On Error GoTo ErrorHandler:
If IsNull([cboUser]) = True Then 'Check UserName
MsgBox "Username is required"
ElseIf IsNull([txtSecret]) = True Then 'Check Secret word
MsgBox "Secret Word is required"
Else
'secretword is to verify users to change their informations. In frmUsers, a user can change his password.
'Compare value of txtSecret with the saved Secret Word in tblUsers
If Me.txtSecret.Value = DLookup("Secret", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") Then
strUser = Me.cboUser.Value 'Set the value of strUser declared as Global Variable
DoCmd.Close acForm, "Secret", acSaveNo
MsgBox "Welcome to Password Area, " & strUser, vbOKOnly, "Welcome"
DoCmd.OpenForm "frmUsers", acNormal, "", "", , acNormal
Else
MsgBox "Invalid Secret Word. Please try again.", vbOKOnly, "Invalid password"
intLogAttempt = intLogAttempt + 1
txtSecret.SetFocus
End If
End If
'Check if the user has 3 wrong log-in attempts and close the application
If intLogAttempt = 3 Then
MsgBox "You do not have access to this database.Please contact admin." & vbCrLf & vbCrLf & _
"Application will exit.", vbCritical, "Restricted Access!"
Application.Quit
End If
ErrorHandler:
End Sub
Please be notified that, the same is used for User Login form and its perfect. But in password form it doesn't verify secret word.
Any help is most appreciated.
Thank you all in advance.
<tamangspace>
I created a login form using the below code. I got the code in this FORUM. thanks for you all. It works perfectly. I don't know how to create codes in vb. I started to read through this forum and learning a bit.
Now I want to create another login form. It would work for password change if any user forgets his password. I used the code to verify 'secret word' and open the 'password change form'. but it is not working. The MsgBox shows "Invalid Secret Word" even if secret word is correct. I paste the code below.
Option Compare Database
'********************************
'********************************
'*** ***
'*** Created by Tamangspace ***
'*** ***
'********************************
'********************************
Private intLogAttempt As Integer
Private Sub cboUser_GotFocus()
cboUser.Dropdown
End Sub
Private Sub cmdExit_Click()
MsgBox "Are you really want to exit this application?"
If response = vbYes Then
Application.Quit
End If
End Sub
Private Sub cmdLogin_Click()
Call Login
End Sub
Private Sub cmdLogin_Enter()
Call Login
End Sub
Public Sub Form_Load()
txtFocus.SetFocus 'txtFocus is a textbox control with height, width and positions set to zero
End Sub
Public Sub Login()
On Error GoTo ErrorHandler:
If IsNull([cboUser]) = True Then 'Check UserName
MsgBox "Username is required"
ElseIf IsNull([txtSecret]) = True Then 'Check Secret word
MsgBox "Secret Word is required"
Else
'secretword is to verify users to change their informations. In frmUsers, a user can change his password.
'Compare value of txtSecret with the saved Secret Word in tblUsers
If Me.txtSecret.Value = DLookup("Secret", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") Then
strUser = Me.cboUser.Value 'Set the value of strUser declared as Global Variable
DoCmd.Close acForm, "Secret", acSaveNo
MsgBox "Welcome to Password Area, " & strUser, vbOKOnly, "Welcome"
DoCmd.OpenForm "frmUsers", acNormal, "", "", , acNormal
Else
MsgBox "Invalid Secret Word. Please try again.", vbOKOnly, "Invalid password"
intLogAttempt = intLogAttempt + 1
txtSecret.SetFocus
End If
End If
'Check if the user has 3 wrong log-in attempts and close the application
If intLogAttempt = 3 Then
MsgBox "You do not have access to this database.Please contact admin." & vbCrLf & vbCrLf & _
"Application will exit.", vbCritical, "Restricted Access!"
Application.Quit
End If
ErrorHandler:
End Sub
Please be notified that, the same is used for User Login form and its perfect. But in password form it doesn't verify secret word.
Any help is most appreciated.
Thank you all in advance.
<tamangspace>