Hey guys I have the code below that I created and it works great for checking if an exact date is in the table, but what I really want is to check if there is a record in the table that matches the year. I am attempting to do this with Datepart and Like.
So I change
To
Code that works fine to match exact dates:
And the code I am trying to use to just check the year (Not Working):
So I change
Code:
If fTableRecordCount("tblSurveillance", "WHERE [fk_SiteID]=" & [fk_SiteID] & " AND [Surv_AuditDue]=" & "#" & DateAdd("yyyy", 1, Me.Qual_InspectionDate.Value) & "#", False) > 0 Then
To
Code:
If fTableRecordCount("tblSurveillance", "WHERE [fk_SiteID]=" & [fk_SiteID] & " AND [Surv_AuditDue] Like *" & DatePart("yyyy", DateAdd("yyyy", 1, Me.Qual_InspectionDate.Value)), False) > 0 Then
Code:
If Me.Qual_Complete.Value = 0 Then End
If MsgBox("Would you like to populate next years Audit?", vbYesNo, "Next Audit") = vbYes Then
If Nz(Me.Qual_InspectionDate.Value, 0) = 0 Then
MsgBox "Sorry it would seem that you dont have an audit date filled in, please update that field", vbCritical, "Missing Data"
Me.Qual_Complete.Value = 0
End
Else
If fTableRecordCount("tblSurveillance", "WHERE [fk_SiteID]=" & [fk_SiteID] & " AND [Surv_AuditDue]=" & "#" & DateAdd("yyyy", 1, Me.Qual_InspectionDate.Value) & "#", False) > 0 Then
MsgBox "Record allready added, no new record was needed", vbOKOnly, "No Change Made"
End
Else
DoCmd.RunSQL "INSERT INTO [tblSurveillance] ([fk_SiteID], [Surv_AuditDue]) VALUES (" & Me.fk_SiteID.Value & "," & "#" & DateAdd("yyyy", 1, Me.Qual_InspectionDate.Value) & "#);"
End If
End If
Else
End
End If
End Sub
And the code I am trying to use to just check the year (Not Working):
Code:
Private Sub Qual_Complete_AfterUpdate()
If Me.Qual_Complete.Value = 0 Then End
If MsgBox("Would you like to populate next years Audit?", vbYesNo, "Next Audit") = vbYes Then
If Nz(Me.Qual_InspectionDate.Value, 0) = 0 Then
MsgBox "Sorry it would seem that you dont have an audit date filled in, please update that field", vbCritical, "Missing Data"
Me.Qual_Complete.Value = 0
End
Else
If fTableRecordCount("tblSurveillance", "WHERE [fk_SiteID]=" & [fk_SiteID] & " AND [Surv_AuditDue] Like *" & DatePart("yyyy", DateAdd("yyyy", 1, Me.Qual_InspectionDate.Value)), False) > 0 Then
MsgBox "Record allready added, no new record was needed", vbOKOnly, "No Change Made"
End
Else
DoCmd.RunSQL "INSERT INTO [tblSurveillance] ([fk_SiteID], [Surv_AuditDue]) VALUES (" & Me.fk_SiteID.Value & "," & "#" & DateAdd("yyyy", 1, Me.Qual_InspectionDate.Value) & "#);"
End If
End If
Else
End
End If
End Sub