Open report to current year

B

Billy B

I have a form with a combo box for the user to select criteria to open a
report. The following code works but I want to add the criteria that the
records displayed only the current year not all years. Any help will be
appreciated.

Private Sub cmdListCodes_Click()
Dim strFilter As String
Dim varItem As Variant

With lstCodeNumbers
If .MultiSelect = 0 Then
strFilter = "
Code:
 = " & .Value
Else
For Each varItem In .ItemsSelected
strFilter = strFilter & "," & .ItemData(varItem)
Next varItem

If Len(strFilter) > 0 Then
If .ItemsSelected.Count = 1 Then
strFilter = "[Code] = " & Mid$(strFilter, 2)
Else
strFilter = "[Code] In(" & Mid$(strFilter, 2) & ")"
End If
End If
End If
End With

'Clear the listbox selected items
With lstCodeNumbers
For Each varItem In .ItemsSelected
.Selected(varItem) = False
Next varItem
End With

'Open the report with the selected Codes
DoCmd.OpenReport "rptTestDescCode", acViewPreview, WhereCondition:=strFilter

End Sub
 
P

PieterLinden via AccessMonster.com

You mean to tell us that you got the hard part down and you couldn't figure
out the easy part???
You just need to tack on the filter for dates... something like

WHERE ...
AND Year([DateField]) = Year(Date())
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top