G
Guest
I'm two weeks old with Access so be gentle.
I'm trying to create a generic password system for a working timesheet form
I have. I don't need high security, I just need to keep the employees filling
out their own timesheet instead of accidently someone elses.
There are 18 employees at my company.
This is my Form_Login code so far:
---------------------------------------------
Option Compare Database
Option Explicit
---------------------------------------------
Private Sub Cancel_Click()
DoCmd.Close
End Sub
---------------------------------------------
Private Sub Submit_Click()
Dim stDocName As String
stDocName = "Password"
DoCmd.OpenForm stDocName
Exit_Submit_Click:
Exit Sub
Err_Submit_Click:
MsgBox err.Description
Resume Exit_Submit_Click
End Sub
__________________________________________________
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
----------------------------------------------------------------------
This my From_Password code:
---------------------------------------------
Option Explicit
---------------------------------------------
Private Sub Form_Load()
gOkToClose = False
' number of tries
gintPasswordFlag = 1
End Sub
---------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
If Not gOkToClose Then
Cancel = True
End If
End Sub
---------------------------------------------
Private Sub PASSWORD_AfterUpdate()
On Error GoTo err_PASSWORD_AfterUpdate
Dim strName As String
Dim strPassword As String
strName = Forms!login1.Login
strPassword = Me![Password]
If StrComp(Nz(DLookup("[Password]", "UserDef", "User_Name ='" & strName &
"'"), ""), strPassword, 0) = 0 Then
gOkToClose = True
Dim Employee
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
DoCmd.Close A_FORM, "Password"
Else
' three tries
Select Case gintPasswordFlag
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintPasswordFlag = gintPasswordFlag + 1
Case Else
DoCmd.Beep
DoCmd.OpenForm "Fail"
End Select
End If
exit_PASSWORD_AfterUpdate:
Exit Sub
err_PASSWORD_AfterUpdate:
MsgBox "Error " & err & ": " & Error$, 0, "Password"
Resume exit_PASSWORD_AfterUpdate
End Sub
---------------------------------------------------------------------
Most of this code I got from very helpful people on here.
My biggest problem is designing my tables to work with this code.
I've been given suggestions to create Table_UserDef to hold Passowrd info
and reference Form_Login that has a dropdown of Employees and use the Dlookup
statement in my code. However, I'm confused of how Dlookup works with my
tables and where to put the info in my tables Dlookup needs to work.
How it (is supposed to) works:
Employee clicks on Login.htm (I will have to create) and selects thier name
from a dropdown list and clicks submit. A password box pops up and if
correctlty entered, closes and the timesheet Form pops up, ready for that
employee to fill in date, hours, etc..
I'm lost with the tables...please help.
I'm trying to create a generic password system for a working timesheet form
I have. I don't need high security, I just need to keep the employees filling
out their own timesheet instead of accidently someone elses.
There are 18 employees at my company.
This is my Form_Login code so far:
---------------------------------------------
Option Compare Database
Option Explicit
---------------------------------------------
Private Sub Cancel_Click()
DoCmd.Close
End Sub
---------------------------------------------
Private Sub Submit_Click()
Dim stDocName As String
stDocName = "Password"
DoCmd.OpenForm stDocName
Exit_Submit_Click:
Exit Sub
Err_Submit_Click:
MsgBox err.Description
Resume Exit_Submit_Click
End Sub
__________________________________________________
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
----------------------------------------------------------------------
This my From_Password code:
---------------------------------------------
Option Explicit
---------------------------------------------
Private Sub Form_Load()
gOkToClose = False
' number of tries
gintPasswordFlag = 1
End Sub
---------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
If Not gOkToClose Then
Cancel = True
End If
End Sub
---------------------------------------------
Private Sub PASSWORD_AfterUpdate()
On Error GoTo err_PASSWORD_AfterUpdate
Dim strName As String
Dim strPassword As String
strName = Forms!login1.Login
strPassword = Me![Password]
If StrComp(Nz(DLookup("[Password]", "UserDef", "User_Name ='" & strName &
"'"), ""), strPassword, 0) = 0 Then
gOkToClose = True
Dim Employee
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
DoCmd.Close A_FORM, "Password"
Else
' three tries
Select Case gintPasswordFlag
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintPasswordFlag = gintPasswordFlag + 1
Case Else
DoCmd.Beep
DoCmd.OpenForm "Fail"
End Select
End If
exit_PASSWORD_AfterUpdate:
Exit Sub
err_PASSWORD_AfterUpdate:
MsgBox "Error " & err & ": " & Error$, 0, "Password"
Resume exit_PASSWORD_AfterUpdate
End Sub
---------------------------------------------------------------------
Most of this code I got from very helpful people on here.
My biggest problem is designing my tables to work with this code.
I've been given suggestions to create Table_UserDef to hold Passowrd info
and reference Form_Login that has a dropdown of Employees and use the Dlookup
statement in my code. However, I'm confused of how Dlookup works with my
tables and where to put the info in my tables Dlookup needs to work.
How it (is supposed to) works:
Employee clicks on Login.htm (I will have to create) and selects thier name
from a dropdown list and clicks submit. A password box pops up and if
correctlty entered, closes and the timesheet Form pops up, ready for that
employee to fill in date, hours, etc..
I'm lost with the tables...please help.