I am sort of new to this whole Access thing. I use Access 2007 and I have a login form for a table. I have three fields in the table UserID, Username and Password. I have a form that has the following code for user login:
Option Compare Database
Private intLogonAttempts As Integer
Private Sub cmdLogin_Click()
'Check to see if data is entered into the Username combo box
If IsNull(Me.cboUsername) Or Me.cboUsername = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboUsername.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check value of password in tblLogin to see if this matches value chosen in combo box
If Me.txtPassword.Value = DLookup("Password", "tblLogin", "[UserID]=" & Me.cboUsername.Value) Then
MyUserID = Me.cboUsername.Value
'Close logon form and open splash screen
DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.OpenForm "frmMain"
Else
MsgBox "Password Invalid. Please Try Again", vbCritical + vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Private Sub cmdCancel_Click()
DoCmd.Quit
End Sub
Problem is:
When I log a user in I would like them to see only records that they created and not anyone else's. Subsequent tables have a field "EnteredBy" which works just fine. If I enter data manually the records do show up under the correct User ID in relation to EnteredBy field. How do I make records show up on a form, only those created by the specific user?