Form/Report/Filter

  • Thread starter Thread starter Vinnie
  • Start date Start date
V

Vinnie

Hello,

I have created my form and it works great.
I have created the Report I want, that works as well.
Question: I would like to have a CmdBtn on the Form which opens the report,
but only for the Record currently on the Form. I'm guessing this would be
some sorta filter, but I'm just not sure how to go about doing this.
Figured Ill post b4 I start reading articles that are most likely more
advanced than what I am actually trying to do.

Appreciated !

ps: you guys are awesome, MVP's "unselfishly helping people do their jobs
for free, for years" !

Vinnie
 
Vinnie said:
Hello,

I have created my form and it works great.
I have created the Report I want, that works as well.
Question: I would like to have a CmdBtn on the Form which opens the
report, but only for the Record currently on the Form. I'm guessing
this would be some sorta filter, but I'm just not sure how to go
about doing this. Figured Ill post b4 I start reading articles that
are most likely more advanced than what I am actually trying to do.

Appreciated !

ps: you guys are awesome, MVP's "unselfishly helping people do their
jobs for free, for years" !

Vinnie

The fourth argument for the OpenReport method which is what your button would
invoke is an optional WHERE clause that will filter the report being opened. A
simple example where both the form and report contain a numeric field [ID] that
we want to filter on...

DoCmd.OpenReport "ReportName", acViewPreview,,"[ID] = " & Me![ID]
 
Rick, my apologies, I replied to you and not the Newsgroup, my bad.

Heres my question:

When you say the Fourth argument, are you talking about on a Macro? If so,
do I enter anything in the Third Argument (Filter Name) ?

Vinnie






Rick Brandt said:
Vinnie said:
Hello,

I have created my form and it works great.
I have created the Report I want, that works as well.
Question: I would like to have a CmdBtn on the Form which opens the
report, but only for the Record currently on the Form. I'm guessing
this would be some sorta filter, but I'm just not sure how to go
about doing this. Figured Ill post b4 I start reading articles that
are most likely more advanced than what I am actually trying to do.

Appreciated !

ps: you guys are awesome, MVP's "unselfishly helping people do their
jobs for free, for years" !

Vinnie

The fourth argument for the OpenReport method which is what your button
would invoke is an optional WHERE clause that will filter the report being
opened. A simple example where both the form and report contain a numeric
field [ID] that we want to filter on...

DoCmd.OpenReport "ReportName", acViewPreview,,"[ID] = " & Me![ID]
 
Vinnie said:
Rick, my apologies, I replied to you and not the Newsgroup, my bad.

Heres my question:

When you say the Fourth argument, are you talking about on a Macro? If so, do
I enter anything in the Third Argument (Filter Name) ?

I never use macros. My example was VBA code, but if I understand correctly then
no you would not. Just as my expression had some commas with "nothing" between
them as placeholders for unused arguments you would leave the FilterName
argument empty
 
So when you say fourth, you mean like this example?

1)Option Compare Database
Option Explicit


2) Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Canceling report..."
Cancel = -1
End Sub
3) Private Sub Report_Close()
DoCmd.Close acForm, "Print Invoice"
End Sub
4) Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenReport "ReportName", acViewPreview,,"[ID] = " & Me![ID]

End Sub
 
Vinnie said:
So when you say fourth, you mean like this example?[snip]
4) Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenReport "ReportName", acViewPreview,,"[ID] = " & Me![ID]

End Sub

Yes. The first argument is the report name. The second determines whether the
report is printed or previewed, the third is the name of a query/table filter
(not used) and the fourth is the WHERE clause that applies the filter.
 
perfect, thanks Rick.



Rick Brandt said:
Vinnie said:
So when you say fourth, you mean like this example?[snip]
4) Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenReport "ReportName", acViewPreview,,"[ID] = " & Me![ID]

End Sub

Yes. The first argument is the report name. The second determines
whether the report is printed or previewed, the third is the name of a
query/table filter (not used) and the fourth is the WHERE clause that
applies the filter.
 
Back
Top