Connect with Expertise | Find Experts, Get Answers, Share Insights

My Visual Basic

 
Join Date: May 2007
Posts: 1
#1: May 14 '07
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

JConsulting's Avatar
E
C
 
Join Date: Apr 2007
Location: Houston
Posts: 601
#2: May 14 '07

re: My Visual Basic


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
Reply