only filtered records on report

eighthundred

Registered User.
Local time
Today, 15:37
Joined
Aug 15, 2005
Messages
11
i've created a form base on a query, and other users will work on it (mainly filter). then i created a report base on the same query...
what i want is a "print" button on the form which will print the report, not all records, but only the filtered records after user applied their filters...
since users will apply different filters each time, it's quite impossible to make all different filters as query...
any idea?
 
Pass the filter info as the WhereCondition of the OpenReport.

DoCmd.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs)
 
ruralguy,
it's doesn't seems work on me. can you give me a example, my code looks like this now...

**********
Private Sub Command76_Click()
On Error GoTo Err_Command76_Click

Dim stDocName As String

stDocName = "rp Order 2005"
DoCmd.OpenReport stDocName, acPreview

Exit_Command76_Click:
Exit Sub

Err_Command76_Click:
MsgBox Err.Description
Resume Exit_Command76_Click

End Sub
 
DoCmd.OpenReport stDocName, acPreview,,Criteria here

DoCmd.OpenReport stDocName, acPreview,,"FieldID = " & Me.FieldID

Just change FieldID to your Primary Key field.

Dave
 
Oldsoftboss said:
DoCmd.OpenReport stDocName, acPreview,,"FieldID = " & Me.FieldID
Dave

this only print the one record that is selecting...
suppose my db has 1000 record.
after a user apply some filters, the form will show "1 of 120 (filtered)."
and i want the report to print out that 120 records, not 1000, not 1...
 
RuralGuy said:
Pass the filter info as the WhereCondition of the OpenReport.

DoCmd.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs)

how? there's no fixed filter, so there's no "FilterName" ...
and "WhereCondition" is also not fixed ...
 
Just as Dave (Oldsoftboss) indicated, the WhereCondition is the filter without the word Where. It can be as dynamic as you wish and is simply a string of your "Filter" criteria. If you want assistance writing the WhereCondition string, post one of your filters and someone can help.
 
Warning: fresh newb

Hello... I was searching around for something exactly like this. Unfortunately I do not know how to complete this code to perform the action eighthundred was looking for.

What kind of instructions should I be putting in the "criteria here" space? If someone could post an example it would be MUCH appreciated!

Thanks!

Claus
 
Oldsoftboss provided a suggestion with:
DoCmd.OpenReport stDocName, acPreview,,"FieldID = " & Me.FieldID
 
gotcha, I thought he meant to include both statements. my bad... like i said, I'm a noob :D
 
ok, so i used the suggested code, and I get the following:

When I filter and click the button corresponding to the code above, I get a preview of only the record that is currently showing on the form. What I would like is for the function to produce a report for all filtered records. Is this possible? :confused:
 
I'm sorry, I can't find the code for the individual filter.

When I filter, I am in the form screen, right click on a field, select filter by selection. In the specific case that I am performing right now it finds 3 of 5 records. I would like then to have a button that would pull up a report that would only show those 3 records. Currently the button I have loaded with the code above creates a report with only the one record that is currently showing on the screen. The filter will not be a consant field or a constant value. The end user needs to be able to filter based on any random field for any random value.

Here is all the code I have for the form:

Private Sub Command22_Click()
Dim stDocName As String

On Error GoTo Err_Command47_Click

DoCmd.RunCommand acCmdSaveRecord
stDocName = "test"
DoCmd.OpenReport stDocName, acViewPreview, , "[CommentID] = " & Me![CommentID]

Exit_Command47_Click:
Exit Sub

Err_Command47_Click:
MsgBox Err.Description
Resume Exit_Command47_Click
End Sub
Private Sub Command26_Click()
On Error GoTo Err_Command26_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 0, 2, acMenuVer70

Exit_Command26_Click:
Exit Sub

Err_Command26_Click:
MsgBox Err.Description
Resume Exit_Command26_Click

End Sub
Private Sub Command27_Click()
On Error GoTo Err_Command27_Click


DoCmd.Close

Exit_Command27_Click:
Exit Sub

Err_Command27_Click:
MsgBox Err.Description
Resume Exit_Command27_Click

End Sub
Private Sub Command28_Click()
On Error GoTo Err_Command28_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

Exit_Command28_Click:
Exit Sub

Err_Command28_Click:
MsgBox Err.Description
Resume Exit_Command28_Click

End Sub
Private Sub Combo29_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[CommentID] = " & Str(Nz(Me![Combo29], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Private Sub Command33_Click()
On Error GoTo Err_Command33_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

Exit_Command33_Click:
Exit Sub

Err_Command33_Click:
MsgBox Err.Description
Resume Exit_Command33_Click

End Sub



thanks!
 

Users who are viewing this thread

Back
Top Bottom