in message
I am writing a simple app with 2 different reports. I am using a Switch
Board as my menu and each report is called via the Open Report from the menu.
I would prefer that the reports just print directly instead of going into
print preview mode. Can anyone help?
The built in Access Switchboard Manager?
You have several options.
1. You could design your own "Switchboard-type" form and
launch all your procedures from there. Most, if not all, experts
prefer to build their own unbound forms for this purpose and
avoid using the Switchboard Manager.
2. You can change the Switchboard code a little bit to
achieve your desired result. The Switchboard automatically
will open a report in preview mode. If you change the code to
print the report then ALL reports will automatically print
launched from the Switchboard which is probably not a good thing.
If you would like to have the best of both worlds, follow these
instructions on a BACK-UP COPY.
Open the Switchboard code. Find the area that has this:
' Constants for the commands that can be executed.
Const conCmdGotoSwitchboard = 1
Const conCmdOpenFormAdd = 2
Const conCmdOpenFormBrowse = 3
Const conCmdOpenReport = 4
Const conCmdCustomizeSwitchboard = 5
Const conCmdExitApplication = 6
Const conCmdRunMacro = 7
Const conCmdRunCode = 8
Add one more line to the list like this:
Const conCmdPrintReport = 9
Now go a little further down the code until you come to
this area:
' Open a form.
Case conCmdOpenFormBrowse
DoCmd.OpenForm rst![Argument]
' Open a report.
Case conCmdOpenReport
DoCmd.OpenReport rst![Argument], acPreview
In between these two areas we want to add another one for
print report. Add in this new code in the middle so it
looks like this:
' Open a form.
Case conCmdOpenFormBrowse
DoCmd.OpenForm rst![Argument]
' Print a report.
Case conCmdPrintReport
DoCmd.OpenReport rst![Argument]
' Open a report.
Case conCmdOpenReport
DoCmd.OpenReport rst![Argument], acPreview
Compile and save the form.
Now you will NOT be able to use the Switchboard Wizard to
use this option. The Wizard will only use the 8 pre-
defined options. To automatically print a report you will
need to go directly to the Switchboard Items TABLE and add
it yourself. If you study the records you will figure out
what is going on. Just use the number 9 in the Command
field to print a report without previewing it.
3. In the Switchboard Manager, select the "Run Code" option.
In the "Function Name" box enter: PrintMyReport
In a standalone module enter:
Public Function PrintMyReport()
DoCmd.OpenReport "ReportNameHere"
End Function
Save the module with a name like basPrintReports.
Hitting that option on the Switchboard form will run the module
code which will print the report. The bad thing about this design
is that you will need to make a different function for EACH report
you want to automatically print.
Hope that helps,