Hi,
I have form with few combo boxes. afterupdate event were with macros so i decided to change them with code and add message if record is not found. i fix all except the one for filtering records by year. macro was like this ="[Godina] = " & "'" & [Screen]. [ActiveControl] & "'" and worked. i added this code but now dont work show only current year (2025) not other years
Private Sub cboYear_AfterUpdate()
Dim yearVal As Variant
yearVal = Nz(Me.cboYear.Value, "")
If yearVal = "" Then
Me.FilterOn = False
Exit Sub
End If
'
Use Year() directly on the real field, not on alias
Me.Filter = "Year([DateOfReceiving]) = " & yearVal
Me.FilterOn = True
' Wait 100 ms to let filter apply before checking record count
DoEvents
If Me.Recordset.RecordCount = 0 Then
MsgBox "No records found for year " & yearVal, vbInformation, "Filter"
Me.FilterOn = False
Me.cboYear = Null
DoCmd.GoToControl "cboYear"
End If
End Sub
I have form with few combo boxes. afterupdate event were with macros so i decided to change them with code and add message if record is not found. i fix all except the one for filtering records by year. macro was like this ="[Godina] = " & "'" & [Screen]. [ActiveControl] & "'" and worked. i added this code but now dont work show only current year (2025) not other years
Private Sub cboYear_AfterUpdate()
Dim yearVal As Variant
yearVal = Nz(Me.cboYear.Value, "")
If yearVal = "" Then
Me.FilterOn = False
Exit Sub
End If
'

Me.Filter = "Year([DateOfReceiving]) = " & yearVal
Me.FilterOn = True
' Wait 100 ms to let filter apply before checking record count
DoEvents
If Me.Recordset.RecordCount = 0 Then
MsgBox "No records found for year " & yearVal, vbInformation, "Filter"
Me.FilterOn = False
Me.cboYear = Null
DoCmd.GoToControl "cboYear"
End If
End Sub