sending results of multi field search form to a report

Rob Ross

Registered User.
Local time
Today, 14:58
Joined
May 24, 2012
Messages
28
I have a multi feild search form that pulls the filtered results to the bottom of the form when the filter is applied. What can I add to this code to send it to a report (AdvSearchReport)? This is the code I use on the page: I have removed a lot of the search fields from this version to make it smaller.

Option Compare Database
Option Explicit

Private Sub cmdFilter_Click()
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to append to.
Const conJetDate = "\#mm\/dd\/yyyy\#" 'The format expected for dates in a JET query string.

'***********************************************************************
'Look at each search box, and build up the criteria string from the non-blank ones.
'***********************************************************************
If Not IsNull(Me.cboFilterHDRC) Then
strWhere = strWhere & "([Issues].[Ticket #] = " & Me.cboFilterHDRC & ") AND "
End If

If Not IsNull(Me.cboFilterIncident) Then
strWhere = strWhere & "([Incident Type] = " & Me.cboFilterIncident & ") AND "
End If

If Not IsNull(Me.txtFilterStatus) Then
strWhere = strWhere & "([Status] Like ""*" & Me.txtFilterStatus & "*"") AND "
End If

If Not IsNull(Me.cboFilterRespons) Then
strWhere = strWhere & "([Issues].[Responsible] = " & Me.cboFilterRespons & ") AND "
End If
'***********************************************************************
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "You must select at least one field to search by.", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
 
You've probably got this sorted already Rob, but heres some code that I use.

The user clicks a command button on the form and the following code open up a report, set the recordsource, saves it, then opens the report.

Regards
Melt

Code:
On Error GoTo Err_cmdOrdersReport_Click

    Dim stDocName As String
    Dim SortOrder As String
    
    stDocName = "rptOrders"
    SortOrder = Me!txtSortOrder
    
    DoCmd.OpenReport stDocName, acViewDesign, , , acHidden
        Reports("rptOrders").RecordSource = Me.RecordSource
            Reports("rptOrders").OrderBy = SortOrder
    
    DoCmd.Save acReport, stDocName
    
    DoCmd.Close acReport, "rptOrders"
    
    DoCmd.OpenReport stDocName, acViewPreview, , , acWindowNormal
 
Exit_cmdOrdersReport_Click:
    Exit Sub

Err_cmdOrdersReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdOrdersReport_Click
 

Users who are viewing this thread

Back
Top Bottom