Hi everyone. I'm attempting to clear a text box in a form, but obviously there's something I'm doing wrong. I've searched online, but can't find anything that helps.
Here's what I'm trying to do: On my Timecard Form, I want to make sure that the user isn't creating a duplicate time card. So once they enter the job name (in a combo box), select the employee (also a combo box), and then the Week Ending date, I have written code for it to check if these three values already exist in any of the records of my Timecard Table. I'm doing this check on the BeforeUpdate on the WeekEnding text box on the form.
Here's the code I've written for the Sub.
Code:
Private Sub WeekEnding_BeforeUpdate(Cancel As Integer)
Dim rstT_Timecards As Recordset
Dim JobID_Table As Integer
Dim EmployeeOnJobsID_Table As Integer
Dim WeekEndingDate_Table As Date
Dim JobID_CurrentRecord As Integer
Dim EmployeeOnJobsID_CurrentRecord As Integer
Set rstT_Timecards = CurrentDb.OpenRecordset(Name:="T_Timecards", Type:=RecordsetTypeEnum.dbOpenSnapshot)
JobID_CurrentRecord = Me.Controls("JobNameComboBox")
EmployeeOnJobsID_CurrentRecord = Me.Controls("EmployeesOnJobsID")
rstT_Timecards.MoveLast
rstT_Timecards.MoveFirst
With rstT_Timecards
Do While Not .EOF
If rstT_Timecards("TimecardID") <> Me.Controls("TimecardID") Then
JobID_Table = .Fields("JobID_notFK")
EmployeeOnJobsID_Table = .Fields("EmployeesOnJobsID")
WeekEndingDate_Table = .Fields("WeekEnding")
If JobID_Table = JobID_CurrentRecord And EmployeeOnJobsID_Table = EmployeeOnJobsID_CurrentRecord And Me.Controls("WeekEnding") = WeekEndingDate_Table Then
MsgBox "A time card for this Job/Person/Position already exists with this Week Ending date. You cannot have more than one. Please select another Week Ending Date."
Me.Controls("WeekEnding").Value = ""
Me.Refresh
rstT_Timecards.Close
Set rstT_Timecards = Nothing
Exit Sub
End If
End If
rstT_Timecards.MoveNext
Loop
End With
rstT_Timecards.Close
Set rstT_Timecards = Nothing
End Sub
I am getting an error message on this line:
Code:
Me.Controls("WeekEnding").Value = ""
I've tried replacing the "" with Null, but I still get the error.
The WeekEnding field is of Data/Time format. Not sure if that matters.
The error I'm getting is:
I can tell I'm in over my head here. I haven't attempted to do any BeforeUpdate commands before, and obviously I'm doing something wrong.