OpenReport Macro

  • Thread starter Thread starter frustrated
  • Start date Start date
F

frustrated

I am trying to use the OpenReport Macro to open a report
filtered on a specific query. I have typed in the query
name in the filter name field, but it does not apply the
filter to the report. The filter works; I have applied it
directly to the report, however it will not work when
applied in the macro. Help!
 
I am trying to use the OpenReport Macro to open a report
filtered on a specific query. I have typed in the query
name in the filter name field, but it does not apply the
filter to the report. The filter works; I have applied it
directly to the report, however it will not work when
applied in the macro. Help!

If you wish help, it would be to your advantage to be a bit more
specific.
Exactly what is your filter? A Query name or a Where Clause?
Which argument did you place it in?
If it is a Where clause, exactly what is it?
What are the field datatypes involved?

Why are you using a macro?
Have you ever written code?
It's as easy to do this in code as a macro and you get the benefit of
error handling.

If you would like to use code to open and filter the report, post back
with the report name, and the exact field and criteria wanted.
 
-----Original Message-----


If you wish help, it would be to your advantage to be a bit more
specific.
Exactly what is your filter? A Query name or a Where Clause?
Which argument did you place it in?
If it is a Where clause, exactly what is it?
What are the field datatypes involved?

Why are you using a macro?
Have you ever written code?
It's as easy to do this in code as a macro and you get the benefit of
error handling.

If you would like to use code to open and filter the report, post back
with the report name, and the exact field and criteria wanted.

--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
.
Thanks for replying

Report name is "Lesson Learned shell"
field name is "Client"
I would like to sort in ascending order
 
Report name is "Lesson Learned shell"
field name is "Client"
I would like to sort in ascending order

I had asked for information on what the filter was. If it was placed
in the filter argument or where clause argument.
Sorting has nothing to do with the above.
How do you wish to filter the report?
By [Client] = what?
Does your query have parameters?
Is the query the record source for the report.

Copy down and post the macro name and actions.

By the way, sorting in a report should be done in the Report's Sorting
and Grouping dialog.
Open the Report in Design view.
Click on View + Sorting and Grouping.

Let's do this using code.
I'll have to make a bunch of guesses here.
I'll assume you have a table or a query as report's record source.
I'll also assume you want to open the report from a form, and filter
the records in the report by using a field on the form that is
displaying the client wanted.
I'll also need to assume that your [Client] field is actually a
ClientID field (regardless of what name you gave it) and has a unique
ID value to identify the correct client, so that no 2 clients have the
same ID.

Add a command button to your form (do Not use the Wizard).
Display the command button's property sheet.

Click on the Events tab.
On the Click event line write
[Event Procedure]
Then click on the button with the 3 dots that appears on that line.
The Code window will open with the cursor positioned between 2 already
existing lines.

Between those 2 lines write:

On Error GoTo Err_Handler
DoCmd.OpenReport ""Lesson Learned shell", acViewPreview,
,"[ClientIDfield ] = " & Me!ClientIDControl
Exit_This_Sub:
Exit Sub
Err_Handler:
MsgBox "Error #: " & err.Number & " " & err.Description
Resume Exit_This_Sub


That's all you need ... IF....
The Client field is unique, is a Number datatype, and is displayed in
the active record shown on your form.

If the [ClientID] field is actually a Text datatype, then change the
above to:

DoCmd.OpenReport ""Lesson Learned shell", acViewPreview, ,
"[ClientIDField] = '" & Me!ClientIDControl & "'"


If the above assumptions are correct, clicking the command button
should open your report and display just records for the client shown
in the form.
 
Back
Top