Hi everyone,
I am a newbie to access and VAB but with the professor "Google's' help I am able to learn, and successfully built part of the database. I have login screen created and all the forms functions as intended, however I am struggling with duplicate records. I have a tblCustomers and tblEmployees, 3 tables for tbllog1,2,3 and three forms where user will enters data. When user enters data, forms auto fills the UserID field based on current user logged in, but upon clicking submit, it created duplicate userid in tblemployees. I try to figured it out myself but no luck so far. Please help.
Login screen code:
Code:
Option Compare DatabaseOption Explicit
Private Sub BtnExit_Click()
Application.Quit
End Sub
Private Sub BtnLogin_Click()
Dim rs As Recordset
'Check to see if data is entered into Username
If IsNull(Me.TxtUserID) Then
MsgBox "Please enter a UserID.", vbOKOnly, "Required Data"
Me.TxtUserID.SetFocus
Exit Sub
End If
'Check to see if data is entered into Password
If IsNull(Me.TxtPassword) Then
MsgBox "You must provide a password.", vbOKOnly, "Required Data"
Me.TxtPassword.SetFocus
Exit Sub
End If
'Lookup correct password for username entered in Username
Set rs = CurrentDb.OpenRecordset("tblEmployee", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserId='" & Me.TxtUserID & "'"
If rs.NoMatch = True Then
MsgBox "Incorrect User Name."
Me.TxtUserID.SetFocus
Exit Sub
TempVars.Add "User", Me.TxtUserID
End If
If rs!Password <> Nz(Me.TxtPassword, "") Then
MsgBox "Incorrect Password."
Me.TxtPassword.SetFocus
Exit Sub
End If
Me.Visible = False
DoCmd.OpenForm "FrmMainMenu"
End Sub
Auto userid filled code
Code:
Private Sub Text21_GotFocus()Me.Text21.Value = Forms!Login!TxtUserID
End Sub