By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

My Visual Basic

P: 1
Can you guys help me. I'm having problems trying to build a criteria for my srtYear field. Do you guys have any solutions?

Private Sub cmdApplyFilter_Click()
Dim strMonth As String
Dim strYear As String
Dim strFilter As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "rptTracking") <> acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build criteria string for Month field
If IsNull(Me.cboMonth.Value) Then
strMonth = "Like '*'"
Else
strMonth = "='" & Me.cboMonth.Value & "'"
End If
' Build criteria string for Year field
If IsNull(Me.cboYear.Value) Then
strYear = "Like '*'"
Else
strYear = "='" & Me.cboYear.Value & "'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[Month] " & strMonth & " AND [Year] " & strYear
' Apply the filter and switch it on
With Reports![rptTracking]
.Filter = strFilter
.FilterOn = True
End With
End Sub

Private Sub cmdRemoveFilter_Click()
On Error Resume Next
' Switch the filter off
Reports![rptTracking].FilterOn = False
End Sub
May 14 '07 #1
Share this Question
Share on Google+
1 Reply


JConsulting
Expert 100+
P: 603
Can you guys help me. I'm having problems trying to build a criteria for my srtYear field. Do you guys have any solutions?

Private Sub cmdApplyFilter_Click()
Dim strMonth As String
Dim strYear As String
Dim strFilter As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "rptTracking") <> acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build criteria string for Month field
If IsNull(Me.cboMonth.Value) Then
strMonth = "Like '*'"
Else
strMonth = "='" & Me.cboMonth.Value & "'"
End If
' Build criteria string for Year field
If IsNull(Me.cboYear.Value) Then
strYear = "Like '*'"
Else
strYear = "='" & Me.cboYear.Value & "'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[Month] " & strMonth & " AND [Year] " & strYear
' Apply the filter and switch it on
With Reports![rptTracking]
.Filter = strFilter
.FilterOn = True
End With
End Sub

Private Sub cmdRemoveFilter_Click()
On Error Resume Next
' Switch the filter off
Reports![rptTracking].FilterOn = False
End Sub
Expand|Select|Wrap|Line Numbers
  1. Dim blMonth As Boolean
  2. Dim blYear As Boolean
  3. blMonth = True
  4. blYear = True
  5. ' Build criteria string for Month field
  6. If Nz(Me.cboMonth, 0) = 0 Then
  7. blMonth = False
  8. Else
  9. strMonth = "='" & Me.cboMonth & "'"
  10. End If
  11. ' Build criteria string for Year field
  12. If Nz(Me.cboYear, 0) = 0 Then
  13. blYear = False
  14. Else
  15. strYear = "='" & Me.cboYear.Value & "'"
  16. End If
  17. ' Combine criteria strings into a WHERE clause for the filter
  18. If blMonth And blYear Then
  19. strFilter = "[Month] =" & strMonth & " AND [Year] =" & strYear
  20. ' Apply the filter and switch it on
  21. With Reports![rptTracking]
  22. .Filter = strFilter
  23. .FilterOn = True
  24. End With
  25. End If
  26.  
J
May 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.