We're using the following code to try and create a report from a mulit-variable search form. We believe its "supposed to" work - but (guess what!) it doesn't. Any advice would be appreciated.
THE SEARCH BUTTON
THE FILTER
THE REPORT BUTTON
THE SEARCH BUTTON
Code:
Private Sub btnSearch_Click()
Me.FrmSubPCGSearch.Form.RecordSource = BuildFilter()
Me.FrmSubPCGSearch.Requery
End Sub
THE FILTER
Code:
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim varItem As Variant
Dim intIndex As Integer
varWhere = Null ' Main filter
' Check for ProjectID
If Me.cmboProjectID > 0 Then
varWhere = varWhere & "[ProjectID] = " & Me.cmboProjectID & " AND "
End If
' Check for Issue Category
If Me.cmbIssueCategoryID > 0 Then
varWhere = varWhere & "[CategoryID] = " & Me.cmbIssueCategoryID & " AND "
End If
' Check for Issue Priority
If Me.cmboIssuePriorityID > 0 Then
varWhere = varWhere & "[PriorityID] = " & Me.cmboIssuePriorityID & " AND "
End If
' Check for Issue Resolution Status
If Me.cmbResolutionStatusID > 0 Then
varWhere = varWhere & "[StatusID] = " & Me.cmbResolutionStatusID & " AND "
End If
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
' strip off last "AND" in the filter
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = "SELECT * FROM qryAllPCGData " & varWhere
End Function
THE REPORT BUTTON
Code:
Private Sub Command38_Click()
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "rptqryAllPCGData"
stLinkCriteria = "[ProjectID]=" & Me![ProjectID]
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
End Sub