Nico22
02-26-2015, 03:41 AM
Hey Guys,
im on my practice periode for the university and my predecessor trainee left my an Access database with a LoginService.
Everything works fine, but when im clicking the login button to access the DB I need to press twice.
I've already checked the code to find a double click event for this event but I couldnt find something.
Maybe one of you got an idea.
Greetings from Germany,
Nic
Option Compare Database
Option Explicit
Private Sub cmdCancel_Click()
DoCmd.Quit
End Sub
Private Sub cmdChngPW_Click()
If Me.cmdChngPW.Caption Like "Change*" Then
Me.cmdLogIn.Enabled = False
Me.txtCnfPW.Value = Null
Me.txtCnfPW.Visible = False
Me.txtNewPW.Value = Null
Me.txtNewPW.Locked = False
Me.txtNewPW.Visible = True
Me.txtNewPW.SetFocus
Me.cmdChngPW.ForeColor = 128
Me.cmdChngPW.Caption = "Cancel" & vbCrLf & "Change"
Exit Sub
ElseIf Me.cmdChngPW.Caption Like "Cancel*" Then
Me.cmdLogIn.Enabled = True
Me.txtCnfPW.Value = Null
Me.txtCnfPW.Visible = False
Me.txtNewPW.Value = Null
'Me.txtNewPW.Locked = False
Me.txtNewPW.Visible = False
Me.cmdLogIn.SetFocus
Me.cmdChngPW.ForeColor = 8388608
Me.cmdChngPW.Caption = "Change" & vbCrLf & "Password"
End If
End Sub
Private Sub cmdLogIn_Click()
Dim strSQL As String
' double check for value in userid
If Nz(Me.txtUserID.Value) = "" Then
MsgBox "You must enter a User ID", vbOKOnly + vbCritical, "No User ID Entered"
Me.txtUserID.SetFocus
Exit Sub
End If
' double check for value in user pw
If Nz(Me.txtPW.Value) = "" Then
MsgBox "You must enter your Password", vbOKOnly + vbCritical, "No Password Entered"
Me.txtPW.SetFocus
Exit Sub
End If
' double-check user id entry - prevent a name change
If IsNull(DLookup("[UserID]", "tblUserSecurity_Sec", "[UserID]='" & Me.txtUserID.Value & "' And [pw]='" & Me.txtPW.Value & "'")) Then
MsgBox "Your User ID and Password do not match." & vbCrLf & vbCrLf & _
"Please try again.", vbCritical + vbOKOnly, "Oops!"
Me.LIChk.Value = Me.LIChk.Value + 1
If Me.LIChk.Value > 3 Then
MsgBox "Your User ID and Password still do not match.", vbCritical + vbOKOnly, "No Hacking!"
DoCmd.Quit
End If
Me.txtUserID.SetFocus
Me.txtPW.Value = Null
Me.txtPW.Visible = False
Me.cmdLogIn.Enabled = False
Me.txtNewPW.Value = Null
Me.txtNewPW.Visible = False
Me.txtCnfPW.Value = Null
Me.txtCnfPW.Visible = False
Me.cmdChngPW.Visible = False
Me.cmdSetPW.Visible = False
Exit Sub
End If
'UPDATE USER LOGIN DATE
strSQL = "UPDATE tblUserSecurity_Sec SET tblUserSecurity_Sec.lastsignon = Now() " & _
"WHERE (((tblUserSecurity_Sec.userID)='" & Me.txtUserID.Value & "'));"
CurrentDb.Execute strSQL, dbFailOnError
' message user about log in
If Me.txtCnfPW.Visible = True And Nz(Me.txtCnfPW.Value) <> "" And Me.txtCnfPW.Value <> Me.txtPW.Value Then
MsgBox Me.txtUserID.Value & " as " & TempVars!strSecLvl & " logged in." & vbCrLf & vbCrLf & _
"New password NOT set.", vbOKOnly, "Successfull Login !"
ElseIf Me.txtCnfPW.Visible = True And Nz(Me.txtCnfPW.Value) <> "" And Me.txtCnfPW.Value = Me.txtPW.Value Then
MsgBox Me.txtUserID.Value & " as " & TempVars!strSecLvl & " logged in." & vbCrLf & vbCrLf & _
"New password IS set.", vbOKOnly, "Successfull Login !"
ElseIf Me.txtCnfPW.Visible = False Then
MsgBox Me.txtUserID.Value & " as " & TempVars!strSecLvl & " logged in.", vbOKOnly, "Successful Login !"
End If
' Place your login completion code here
' for purposes of this demo, the user security form is opened
DoCmd.OpenForm "Haupt_Menue_F" ' Main Menu, etc
' close login form after successfull login
DoCmd.Close acForm, "frmLogIn"
End Sub
Private Sub cmdSetPW_Click()
Dim strSQL As String
' change user password
strSQL = "UPDATE tblUserSecurity_Sec SET tblUserSecurity_Sec.pw = '" & Me.txtCnfPW.Value & "' " & _
"WHERE (((tblUserSecurity_Sec.userID)='" & Me.txtUserID.Value & "'));"
CurrentDb.Execute strSQL, dbFailOnError
Me.txtPW.Value = Me.txtCnfPW.Value
MsgBox "New Password Set !", vbOKOnly, "Success!"
Me.cmdLogIn.Enabled = True
Me.cmdLogIn.SetFocus
End Sub
Private Sub Form_Load()
Me.txtPW.Visible = True
Me.cmdCancel.Visible = True
Me.cmdChngPW.Visible = True
Me.cmdSetPW.Visible = True
Me.cmdLogIn.Enabled = True
End Sub
Private Sub Form_Open(Cancel As Integer)
DoCmd.ShowToolbar "Web", acToolbarNo
End Sub
Private Sub Title_Top_DblClick(Cancel As Integer)
DoCmd.Close
End Sub
Private Sub txtCnfPW_AfterUpdate()
' check for value in new user pw confirmation
If Nz(Me.txtCnfPW.Value) = "" Then
MsgBox "You have not entered a confirming password." & vbCrLf & vbCrLf & _
"Please enter your new confirming to continue.", vbOKOnly, "Confirming Password Missing"
Me.txtCnfPW.SetFocus
Exit Sub
End If
' compare/confirm new password
If Me.txtCnfPW.Value = Me.txtNewPW.Value Then
Me.cmdSetPW.Visible = True
Me.cmdSetPW.SetFocus
' lock the password change fields
Me.txtNewPW.Locked = True
Me.txtCnfPW.Locked = True
Else
MsgBox "Password confirmation does not match New Password.", vbOKOnly, "Mismatched Password Confirmation"
Me.txtCnfPW.SetFocus
End If
End Sub
Private Sub txtNewPW_AfterUpdate()
' check for value in new user pw
If Nz(Me.txtNewPW.Value) = "" Then
MsgBox "You have not entered a new password." & vbCrLf & vbCrLf & _
"Please enter your new password to continue.", vbOKOnly, "New Password Missing"
Me.txtNewPW.SetFocus
Exit Sub
End If
Me.txtCnfPW.Locked = False
Me.txtCnfPW.Visible = True
Me.txtCnfPW.SetFocus
End Sub
Private Sub txtPW_AfterUpdate()
' check for value in user pw
If Nz(Me.txtPW.Value) = "" Then
MsgBox "You have not entered a password." & vbCrLf & vbCrLf & _
"Please enter your password to continue.", vbOKOnly, "Password Missing"
Me.txtPW.SetFocus
Exit Sub
End If
' Validate user password and count user pw entry attempts
If DLookup("[pw]", "tblUserSecurity_Sec", "[UserID]='" & Me.txtUserID.Value & "'") <> Me.txtPW.Value Then
Me.PWChk.Value = Me.PWChk.Value + 1
If Me.PWChk.Value > 5 Then
MsgBox "You may not make more than five Password entry attempts.", vbCritical + vbOKOnly, "Oops!"
DoCmd.Quit
End If
MsgBox "The Password for " & Me.txtUserID.Value & " is incorrect." & vbCrLf & _
"Please enter your correct Password or contact your Application " & _
"Administrator.", vbOKOnly, "Password for " & Me.txtUserID.Value & " Incorrect"
Exit Sub
Else
' DETERMINE USER SECURITY LEVEL
' (TempVars!strSecLvl is a TempVars variable set below)
' This is the only place where the text values for 'TempVars!strSecLvl' are set
' "[reado]" = "Read Only" - lowest setting
' "[data]" = "Data Only" - data entry only
' "[sprvsr]" = "Supervisor" - supervisor: arbitrary intermediate security level
' "[admn]" = "Administrator" - administrator: arbitrary management security level
' "[dev]" = "Developer" - developer: top level security level, no constraints
If DLookup("[reado]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = -1 Then
TempVars.Add "strSecLvl", "Read Only"
End If
If DLookup("[data]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = -1 Then
TempVars.Add "strSecLvl", "Data Only"
End If
If DLookup("[sprvsr]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = -1 Then
TempVars.Add "strSecLvl", "Supervisor"
End If
If DLookup("[admn]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = -1 Then
TempVars.Add "strSecLvl", "Administrator"
End If
If DLookup("[dev]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = -1 Then
TempVars.Add "strSecLvl", "Developer"
End If
' DETERMINE Department (SC/PTN, SC/PTP, SC/PTT, FMO und IT)
' (TempVars!Depart is a TempVars variable set below)
' This is the only place where the text values for 'TempVars!Depart' are set
If DLookup("[Department]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = "SC/PTN" Then
TempVars.Add "Depart", "SC/PTN"
End If
If DLookup("[Department]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = "SC/PTP" Then
TempVars.Add "Depart", "SC/PTP"
End If
If DLookup("[Department]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = "SC/PTT" Then
TempVars.Add "Depart", "SC/PTT"
End If
If DLookup("[Department]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = "FMO/PS" Then
TempVars.Add "Depart", "FMO/PS"
End If
If DLookup("[Department]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = "ITP/PL" Then
TempVars.Add "Depart", "ITP/PL"
End If
Me.cmdLogIn.Enabled = True
Me.cmdChngPW.Visible = True
Me.cmdLogIn.SetFocus
End If
End Sub
Private Sub txtUserID_AfterUpdate()
' Validate user id (name)
If IsNull(Me.txtUserID.Value) Or Me.txtUserID.Value = "" Then
MsgBox "Enter your User ID (Name) in the User ID field.", vbOKOnly, "Missing User ID"
Me.txtPW.Value = Null
Me.txtPW.Visible = False
Me.txtUserID.SetFocus
Exit Sub
End If
' count user id entry attempts
If IsNull(DLookup("[UserID]", "tblUserSecurity_Sec", "[UserID]='" & Me.txtUserID.Value & "'")) Then
Me.UIDChk.Value = Me.UIDChk.Value + 1
If Me.UIDChk.Value > 3 Then
MsgBox "You may not make more than three User ID entry attempts.", vbCritical + vbOKOnly, "Oops!"
DoCmd.Quit
End If
MsgBox "Permissions for " & Me.txtUserID.Value & " does not exist." & vbCrLf & _
"Please enter your correct User ID or contact your Application " & _
"Administrator.", vbOKOnly, "User ID " & Me.txtUserID.Value & " Invalid"
Exit Sub
End If
' user id exists, continue
Me.txtPW.Visible = True
Me.txtPW.SetFocus
End Sub
Private Sub txtUserID_GotFocus()
If Me.txtCnfPW.Visible = True Then
Me.txtCnfPW.SetFocus
End If
End Sub
im on my practice periode for the university and my predecessor trainee left my an Access database with a LoginService.
Everything works fine, but when im clicking the login button to access the DB I need to press twice.
I've already checked the code to find a double click event for this event but I couldnt find something.
Maybe one of you got an idea.
Greetings from Germany,
Nic
Option Compare Database
Option Explicit
Private Sub cmdCancel_Click()
DoCmd.Quit
End Sub
Private Sub cmdChngPW_Click()
If Me.cmdChngPW.Caption Like "Change*" Then
Me.cmdLogIn.Enabled = False
Me.txtCnfPW.Value = Null
Me.txtCnfPW.Visible = False
Me.txtNewPW.Value = Null
Me.txtNewPW.Locked = False
Me.txtNewPW.Visible = True
Me.txtNewPW.SetFocus
Me.cmdChngPW.ForeColor = 128
Me.cmdChngPW.Caption = "Cancel" & vbCrLf & "Change"
Exit Sub
ElseIf Me.cmdChngPW.Caption Like "Cancel*" Then
Me.cmdLogIn.Enabled = True
Me.txtCnfPW.Value = Null
Me.txtCnfPW.Visible = False
Me.txtNewPW.Value = Null
'Me.txtNewPW.Locked = False
Me.txtNewPW.Visible = False
Me.cmdLogIn.SetFocus
Me.cmdChngPW.ForeColor = 8388608
Me.cmdChngPW.Caption = "Change" & vbCrLf & "Password"
End If
End Sub
Private Sub cmdLogIn_Click()
Dim strSQL As String
' double check for value in userid
If Nz(Me.txtUserID.Value) = "" Then
MsgBox "You must enter a User ID", vbOKOnly + vbCritical, "No User ID Entered"
Me.txtUserID.SetFocus
Exit Sub
End If
' double check for value in user pw
If Nz(Me.txtPW.Value) = "" Then
MsgBox "You must enter your Password", vbOKOnly + vbCritical, "No Password Entered"
Me.txtPW.SetFocus
Exit Sub
End If
' double-check user id entry - prevent a name change
If IsNull(DLookup("[UserID]", "tblUserSecurity_Sec", "[UserID]='" & Me.txtUserID.Value & "' And [pw]='" & Me.txtPW.Value & "'")) Then
MsgBox "Your User ID and Password do not match." & vbCrLf & vbCrLf & _
"Please try again.", vbCritical + vbOKOnly, "Oops!"
Me.LIChk.Value = Me.LIChk.Value + 1
If Me.LIChk.Value > 3 Then
MsgBox "Your User ID and Password still do not match.", vbCritical + vbOKOnly, "No Hacking!"
DoCmd.Quit
End If
Me.txtUserID.SetFocus
Me.txtPW.Value = Null
Me.txtPW.Visible = False
Me.cmdLogIn.Enabled = False
Me.txtNewPW.Value = Null
Me.txtNewPW.Visible = False
Me.txtCnfPW.Value = Null
Me.txtCnfPW.Visible = False
Me.cmdChngPW.Visible = False
Me.cmdSetPW.Visible = False
Exit Sub
End If
'UPDATE USER LOGIN DATE
strSQL = "UPDATE tblUserSecurity_Sec SET tblUserSecurity_Sec.lastsignon = Now() " & _
"WHERE (((tblUserSecurity_Sec.userID)='" & Me.txtUserID.Value & "'));"
CurrentDb.Execute strSQL, dbFailOnError
' message user about log in
If Me.txtCnfPW.Visible = True And Nz(Me.txtCnfPW.Value) <> "" And Me.txtCnfPW.Value <> Me.txtPW.Value Then
MsgBox Me.txtUserID.Value & " as " & TempVars!strSecLvl & " logged in." & vbCrLf & vbCrLf & _
"New password NOT set.", vbOKOnly, "Successfull Login !"
ElseIf Me.txtCnfPW.Visible = True And Nz(Me.txtCnfPW.Value) <> "" And Me.txtCnfPW.Value = Me.txtPW.Value Then
MsgBox Me.txtUserID.Value & " as " & TempVars!strSecLvl & " logged in." & vbCrLf & vbCrLf & _
"New password IS set.", vbOKOnly, "Successfull Login !"
ElseIf Me.txtCnfPW.Visible = False Then
MsgBox Me.txtUserID.Value & " as " & TempVars!strSecLvl & " logged in.", vbOKOnly, "Successful Login !"
End If
' Place your login completion code here
' for purposes of this demo, the user security form is opened
DoCmd.OpenForm "Haupt_Menue_F" ' Main Menu, etc
' close login form after successfull login
DoCmd.Close acForm, "frmLogIn"
End Sub
Private Sub cmdSetPW_Click()
Dim strSQL As String
' change user password
strSQL = "UPDATE tblUserSecurity_Sec SET tblUserSecurity_Sec.pw = '" & Me.txtCnfPW.Value & "' " & _
"WHERE (((tblUserSecurity_Sec.userID)='" & Me.txtUserID.Value & "'));"
CurrentDb.Execute strSQL, dbFailOnError
Me.txtPW.Value = Me.txtCnfPW.Value
MsgBox "New Password Set !", vbOKOnly, "Success!"
Me.cmdLogIn.Enabled = True
Me.cmdLogIn.SetFocus
End Sub
Private Sub Form_Load()
Me.txtPW.Visible = True
Me.cmdCancel.Visible = True
Me.cmdChngPW.Visible = True
Me.cmdSetPW.Visible = True
Me.cmdLogIn.Enabled = True
End Sub
Private Sub Form_Open(Cancel As Integer)
DoCmd.ShowToolbar "Web", acToolbarNo
End Sub
Private Sub Title_Top_DblClick(Cancel As Integer)
DoCmd.Close
End Sub
Private Sub txtCnfPW_AfterUpdate()
' check for value in new user pw confirmation
If Nz(Me.txtCnfPW.Value) = "" Then
MsgBox "You have not entered a confirming password." & vbCrLf & vbCrLf & _
"Please enter your new confirming to continue.", vbOKOnly, "Confirming Password Missing"
Me.txtCnfPW.SetFocus
Exit Sub
End If
' compare/confirm new password
If Me.txtCnfPW.Value = Me.txtNewPW.Value Then
Me.cmdSetPW.Visible = True
Me.cmdSetPW.SetFocus
' lock the password change fields
Me.txtNewPW.Locked = True
Me.txtCnfPW.Locked = True
Else
MsgBox "Password confirmation does not match New Password.", vbOKOnly, "Mismatched Password Confirmation"
Me.txtCnfPW.SetFocus
End If
End Sub
Private Sub txtNewPW_AfterUpdate()
' check for value in new user pw
If Nz(Me.txtNewPW.Value) = "" Then
MsgBox "You have not entered a new password." & vbCrLf & vbCrLf & _
"Please enter your new password to continue.", vbOKOnly, "New Password Missing"
Me.txtNewPW.SetFocus
Exit Sub
End If
Me.txtCnfPW.Locked = False
Me.txtCnfPW.Visible = True
Me.txtCnfPW.SetFocus
End Sub
Private Sub txtPW_AfterUpdate()
' check for value in user pw
If Nz(Me.txtPW.Value) = "" Then
MsgBox "You have not entered a password." & vbCrLf & vbCrLf & _
"Please enter your password to continue.", vbOKOnly, "Password Missing"
Me.txtPW.SetFocus
Exit Sub
End If
' Validate user password and count user pw entry attempts
If DLookup("[pw]", "tblUserSecurity_Sec", "[UserID]='" & Me.txtUserID.Value & "'") <> Me.txtPW.Value Then
Me.PWChk.Value = Me.PWChk.Value + 1
If Me.PWChk.Value > 5 Then
MsgBox "You may not make more than five Password entry attempts.", vbCritical + vbOKOnly, "Oops!"
DoCmd.Quit
End If
MsgBox "The Password for " & Me.txtUserID.Value & " is incorrect." & vbCrLf & _
"Please enter your correct Password or contact your Application " & _
"Administrator.", vbOKOnly, "Password for " & Me.txtUserID.Value & " Incorrect"
Exit Sub
Else
' DETERMINE USER SECURITY LEVEL
' (TempVars!strSecLvl is a TempVars variable set below)
' This is the only place where the text values for 'TempVars!strSecLvl' are set
' "[reado]" = "Read Only" - lowest setting
' "[data]" = "Data Only" - data entry only
' "[sprvsr]" = "Supervisor" - supervisor: arbitrary intermediate security level
' "[admn]" = "Administrator" - administrator: arbitrary management security level
' "[dev]" = "Developer" - developer: top level security level, no constraints
If DLookup("[reado]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = -1 Then
TempVars.Add "strSecLvl", "Read Only"
End If
If DLookup("[data]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = -1 Then
TempVars.Add "strSecLvl", "Data Only"
End If
If DLookup("[sprvsr]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = -1 Then
TempVars.Add "strSecLvl", "Supervisor"
End If
If DLookup("[admn]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = -1 Then
TempVars.Add "strSecLvl", "Administrator"
End If
If DLookup("[dev]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = -1 Then
TempVars.Add "strSecLvl", "Developer"
End If
' DETERMINE Department (SC/PTN, SC/PTP, SC/PTT, FMO und IT)
' (TempVars!Depart is a TempVars variable set below)
' This is the only place where the text values for 'TempVars!Depart' are set
If DLookup("[Department]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = "SC/PTN" Then
TempVars.Add "Depart", "SC/PTN"
End If
If DLookup("[Department]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = "SC/PTP" Then
TempVars.Add "Depart", "SC/PTP"
End If
If DLookup("[Department]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = "SC/PTT" Then
TempVars.Add "Depart", "SC/PTT"
End If
If DLookup("[Department]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = "FMO/PS" Then
TempVars.Add "Depart", "FMO/PS"
End If
If DLookup("[Department]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'") = "ITP/PL" Then
TempVars.Add "Depart", "ITP/PL"
End If
Me.cmdLogIn.Enabled = True
Me.cmdChngPW.Visible = True
Me.cmdLogIn.SetFocus
End If
End Sub
Private Sub txtUserID_AfterUpdate()
' Validate user id (name)
If IsNull(Me.txtUserID.Value) Or Me.txtUserID.Value = "" Then
MsgBox "Enter your User ID (Name) in the User ID field.", vbOKOnly, "Missing User ID"
Me.txtPW.Value = Null
Me.txtPW.Visible = False
Me.txtUserID.SetFocus
Exit Sub
End If
' count user id entry attempts
If IsNull(DLookup("[UserID]", "tblUserSecurity_Sec", "[UserID]='" & Me.txtUserID.Value & "'")) Then
Me.UIDChk.Value = Me.UIDChk.Value + 1
If Me.UIDChk.Value > 3 Then
MsgBox "You may not make more than three User ID entry attempts.", vbCritical + vbOKOnly, "Oops!"
DoCmd.Quit
End If
MsgBox "Permissions for " & Me.txtUserID.Value & " does not exist." & vbCrLf & _
"Please enter your correct User ID or contact your Application " & _
"Administrator.", vbOKOnly, "User ID " & Me.txtUserID.Value & " Invalid"
Exit Sub
End If
' user id exists, continue
Me.txtPW.Visible = True
Me.txtPW.SetFocus
End Sub
Private Sub txtUserID_GotFocus()
If Me.txtCnfPW.Visible = True Then
Me.txtCnfPW.SetFocus
End If
End Sub