
Originally Posted by
Eranka
HI Ridders
I tried your code as well
Code:
CurrentDb.Execute "INSERT INTO UserLog ([User_name], [Log_Time])" & "VALUES ('" & Me.txtUserName & "','" & Now() & "')"
it give me the same error
2467.
Do i have to put the above code inside the If else statement?
"yes encryption thread, i tried that but it seems bit complex so went with password format.
"
The fact that you get the same error with both my code & that by Chris, suggests the issue is with your code
Unfortunately your code is incomplete & the first line is incorrect
I've indented it to try & make sense of the nested If statements
Are you sure your logic is correct?
Select Case would be easier to follow
Suggest placement in BLUE but that may not be correct
Code:
Sub Eranka()
Dim User As String, UserLevel As Integer, TempPass As String
Dim ID As Integer
Dim UserName As String
Dim TempID As String
If IsNull(Me.txtUserName) Then
MsgBox "Please Enter User Name", vbInformation, "Username required"
Me.txtUserName.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please Enter Password", vbInformation, "Password required"
Me.txtPassword.SetFocus
Else
If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin = '" & Me.txtUserName.Value & "' And UserPassword = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Invalid Username or Password!"
Else
TempID = Me.txtUserName.Value
UserName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
UserLevel = DLookup("[UserSecurity]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
TempPass = DLookup("[UserPassword]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
UserLogin = DLookup("[UserLogin]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
ID = DLookup("[ID]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
CurrentDb.Execute "INSERT INTO UserLog ([User_name], [Log_Time])" & "VALUES ('" & Me.txtUserName & "','" & Now() & "')"
DoCmd.Close 'move this later?
If (TempPass = "password") Then
MsgBox "Please change Password", vbInformation, "New password required"
DoCmd.OpenForm "frmUserinfo", , , "[ID] = " & ID
Else
'open different form according to user level
If UserLevel = 1 Then ' for admin
DoCmd.OpenForm "Navigation Form"
ElseIf UserLevel = 2 Then ' for academic
DoCmd.OpenForm "Navigation Form"
ElseIf UserLevel = 3 Then ' for exam
DoCmd.OpenForm "Navigation Form"
Else
DoCmd.OpenForm "Main_Menu_2"
Forms![Main_Menu_2]!Command19.Enabled = False
End If
End If
End If
End If
End Sub
As a general rule, open the other form BEFORE closing the current one.
This helps ensure any variables are carried through to the new form
As for encryption, it isn't simple but if you are storing passwords in your app without encrypting them you are asking for trouble BIG TIME
You will render yourself liable for big fines under the new GDPR law
The password format is EASY to break. Users just need to remove / replace the format