Open a report in two different ways

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Please bear with me - I'm fairly new at this!

I currently have a print button on a form that prints a report with the
form's filter. I would like to also offer the option of printing the report
from a menu with a pop-up dialog box to enter filter criteria. Do I need to
have two different copies of the report responding to two different queries?
It seems there must be an easier way.

Thank you so much for all I've learned from this group!
 
You dont need to reports or two queries
Have two buttons, the first one open the report with a filter from the form
docmd.OpenReport "ReportName",,,"MyField=" & me.FieldName

The second button prompt first a request to enter a value and then run the
report

dim MyValue as string
MyValue = inputbox ("enter value")
if MyValue <> "" then
docmd.OpenReport "ReportName",,,"MyField=" & MyValue
end if
 
I appreciate your response. I'm not sure whether I explained myself
properly, though. When the form is open, I have a print button that will
print the report (either with or without a filter, depending on the form's
status). What I would like to do, though, is add the report to a list on a
menu bar that would enable the user to access the report without the form
being open. I would, however, need a dialog box that would allow for a
filter. I hope this makes sense. I also hope I didn't misunderstand your
answer. I thought you meant to put two control buttons on the form.
 
Then create a function in a module and run this code
function RunMyReport()
dim MyValue as string
MyValue = inputbox ("enter value")
if MyValue <> "" then
docmd.OpenReport "ReportName",,,"MyField=" & MyValue
end if
End function
Then create a macro to run this function, in the action of the macro select
"RunCode", on the bottom choose the name of the function RunMyReport().

Add the macro to the toolbar, right click on the toolbar, select customize,
list the macros, and drag the desire macro to the toolbar.
 
Perfect! Thank you so much!

Ofer said:
Then create a function in a module and run this code
function RunMyReport()
dim MyValue as string
MyValue = inputbox ("enter value")
if MyValue <> "" then
docmd.OpenReport "ReportName",,,"MyField=" & MyValue
end if
End function
Then create a macro to run this function, in the action of the macro select
"RunCode", on the bottom choose the name of the function RunMyReport().

Add the macro to the toolbar, right click on the toolbar, select customize,
list the macros, and drag the desire macro to the toolbar.
 
Back
Top