Keep in mind that I'm new to VBA with access. so try to break it down as much as possible.
I just got some fantastic help here earlier so I hope for the same luck. I'm doing a basic timeclock design. When the employee opens the form they are given a combobox (UserNameSelect ), a textbox (PasswordEntry) and 4 command buttons: cmdClockIn, CmdLunchOut, CmdLunchIn, CmdClockOut.
the person selects their username from a dropdown menu and proceeds to enter their password in the textbox. They click Clock in and it will automatically create a new record and fill in their employee id, first name, Last name, The date, and the time of clocking in.
This is where my error comes in. When it tries to update the database it throws the error Run-time error '3201':
You cannot add or change a record because a related record is required in table 'Employee Information'.
I'm very confused as to what this is getting at. There are no fields in the employee information table that are required. I'm wondering if it has to do with my relationships and the way they are setup. Anyway any insight possible is greatly appreciated and I'm sure its some simple thing I'm overlooking. Anyway here is my code:
I apologize for this being over 20 lines, but I wanted to make sure I got my entire elseif statement in. I omitted everything else that was working. Like I said at this point I'm wondering if my problem is even in my code or if it's related to my relationships. If it appears that the code is fine and it's something else in my database please let me know so I can go elsewhere for help in finding a solution.
If you happen to have any other suggestions please let me know I'm open to any and all ideas, though I don't want to have this thread go too far off topic. Once again any help or insight is greatly appreciated. Thank you
I just got some fantastic help here earlier so I hope for the same luck. I'm doing a basic timeclock design. When the employee opens the form they are given a combobox (UserNameSelect ), a textbox (PasswordEntry) and 4 command buttons: cmdClockIn, CmdLunchOut, CmdLunchIn, CmdClockOut.
the person selects their username from a dropdown menu and proceeds to enter their password in the textbox. They click Clock in and it will automatically create a new record and fill in their employee id, first name, Last name, The date, and the time of clocking in.
This is where my error comes in. When it tries to update the database it throws the error Run-time error '3201':
You cannot add or change a record because a related record is required in table 'Employee Information'.
I'm very confused as to what this is getting at. There are no fields in the employee information table that are required. I'm wondering if it has to do with my relationships and the way they are setup. Anyway any insight possible is greatly appreciated and I'm sure its some simple thing I'm overlooking. Anyway here is my code:
Code:
Option Compare Database
Private Sub CmdClockIn_Click()
Dim strSQL As String
Dim str_foundPW As String
Dim dbsFloor As DAO.Database
Dim rstTime As DAO.Recordset
Set dbsFloor = CurrentDb
Set rstTime = dbsFloor.OpenRecordset("TblTimeSlip")
If Me.PasswordEntry & vbNullString = "" Then
MsgBox "You must provide your password.", vbOKOnly, "Required Data"
Me.PasswordEntry.SetFocus
ElseIf Me.PasswordEntry <> str_foundPW Then
MsgBox "Incorrect Password.", vbOKOnly, "Required Data"
'Create a new record because this will be the first entry done of the day in the table
ElseIf Me.PasswordEntry = str_foundPW Then
rstTime.AddNew
rstTime("EmpID") = "[EmpID] ='" & Me.UserNameSelect & "'"
rstTime("FName") = DLookup("[EmpFName]", "EmployeeInfo", strSQL)
rstTime("LName") = DLookup("[EmpLName]", "EmployeeInfo", strSQL)
rstTime("DateWorked") = Format(Now(), "mm/dd/yyyy")
rstTime("TimeIn") = time()
rstTime.Update
Exit Sub
End If
End Sub
If you happen to have any other suggestions please let me know I'm open to any and all ideas, though I don't want to have this thread go too far off topic. Once again any help or insight is greatly appreciated. Thank you
Comment