Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Send all filtered records to report

Status
Not open for further replies.

Aliffi

MIS
Jan 9, 2005
51
BE
I have a Form with boxes
and a button , when i write criteria and click the button records are filtered ,on the current form and i can see the result very well, now i want to send all these records to a report after i click the button,
this is the code i have for the button and boxes

------------------------------------------------------
Private Sub Command196_Click()
Dim strWhere As String
Dim frm As Form

'DoCmd.OpenReport "main_report", acViewPreview

Set frm = Forms!filter_report.Form

If Nz(frm!prof, "") <> "" Then
strWhere = "province='" & frm!prof & "'"
End If

If Nz(frm!yeaf, "") <> "" Then
strWhere = "year='" & frm!yeaf & "'"
End If
If Nz(frm!taskmf, "") <> "" Then
strWhere = "task_manager='" & frm!taskmf & "'"
End If

If Nz(frm!msf, "") <> "" Then
strWhere = "main_sector='" & frm!msf & "'"
End If
If Nz(frm!disf, "") <> "" Then
strWhere = "district='" & frm!disf & "'"
End If
If Nz(frm!complf, "") <> "" Then
strWhere = "completed='" & frm!complf & "'"
End If
If Nz(frm!crisf, "") <> "" Then
strWhere = "cris_no='" & frm!crisf & "'"
End If

'======================================================'
If Nz(frm!agenf, "") <> "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND name_of_agency='" & frm!agenf & "'"
Else
strWhere = "name_of_agency='" & frm!agenf & "'"
End If
End If
'======================================================'
If Nz(frm!yeaf, "") <> "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND year='" & frm!yeaf & "'"
Else
strWhere = "year='" & frm!yeaf & "'"
End If
End If
'======================================================'

If Nz(frm!taskmf, "") <> "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND task_manager='" & frm!taskmf & "'"
Else
strWhere = "task_manager='" & frm!taskmf & "'"
End If
End If
'======================================================'
If Nz(frm!msf, "") <> "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND main_sector='" & frm!msf & "'"
Else
strWhere = "main_sector='" & frm!msf & "'"
End If
End If
'======================================================'

If Nz(frm!prof, "") <> "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND province='" & frm!prof & "'"
Else
strWhere = "province='" & frm!prof & "'"
End If
End If
'======================================================'
If Nz(frm!complf, "") <> "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND completed='" & frm!complf & "'"
Else
strWhere = "completed='" & frm!complf & "'"
End If
End If
'======================================================'
If Nz(frm!disf, "") <> "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND district='" & frm!disf & "'"
Else
strWhere = "district='" & frm!disf & "'"
End If
End If
'======================================================'
If Nz(frm!crisf, "") <> "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND cris_no='" & frm!crisf & "'"
Else
strWhere = "cris_no='" & frm!crisf & "'"
End If
End If
'======================================================'
If Len(strWhere) > 0 Then

DoCmd.ApplyFilter , strWhere


Else
MsgBox "Please Enter a Criteria in the boxes", vbExclamation, "Alert"


End If


End Sub
---------------------------------------------------
 
Open the report with a filter (where clause).

Example.
Private Sub PrintReport_Click()
On Error GoTo Err_PrintReport_Click

Dim stDocName As String
Dim WhereClause As String
WhereClause = "username = 'Commerfj'"

stDocName = "Report1"
DoCmd.OpenReport stDocName, acViewPreview, , WhereClause
Exit_PrintReport_Click:
Exit Sub

Err_PrintReport_Click:
MsgBox Err.Description
Resume Exit_PrintReport_Click

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top