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
---------------------------------------------------
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
---------------------------------------------------