CTRL + P or equivalent

G

Guest

Hi,
I have a custom menu bar which has the 'Print...' command on it. This is
just the default which I dragged across from the File menu. This is a little
misleading as the elipsis (...) suggests that there is more to follow, when
in fact there isn't. I need the print dialog box to pop up instead of sending
the report straight to the default printer. Is there a way of assigning the
CTRL + P key combination to a button on the toolbar or something similar?
I've tried using the Sendkeys function in a macro and aslo in a module, but
it keeps erroring.

Thanks
Dave
 
A

Albert D.Kallal

As a general rule, all my custom menu buttions runs vb code.

So, just have your pint, and print preivew menu code run the follwing

The select object command is needed to fix a "focus" bug if you have a form
with a timer function.

For the code that pops up the printer dialog (so the user can change
printers etc).

You can use:

On Error Resume Next
DoCmd.SelectObject acReport, Screen.ActiveReport.Name
DoCmd.RunCommand acCmdPrint

The select object command is needed to fix a "focus" bug if you have a form
with a timer function.

The code to print right to the printer while in preview mode can be:

On Error Resume Next
Dim strReportName as string
strREportName = Screen.ActiveReport.Name
DoCmd.SelectObject acReport, strReportName
DoCmd.PrintOut acPrintAll
 
G

Guest

Thanks Albert.
However, it didn't work. I put that code in a module as a public function
named modPrint. I have a custom Toolbar, which has custom menus. I added a
custom command to one of the menus and referenced the function from the
commands property sheet. When I choose this command while the report is open
I get the following error:
'The expression you entered has a field, control or property that the
database can't find'

Any ideas?
 
V

Van T. Dinh

1. Did you use the same name for the function name as well as the module
name?

Modules and Procedures share the same name space and you will get an error
if a function and a Module have the same name.

2. Did you include the equal sign in front of the function and the
parentheses after the function name (even when the function does not require
any argument)?

For example, the following works for me when I enter in the "On Action"
Property:

= fnTestMenuButton()

(including the equal sign).
 
A

Albert D.Kallal

Van's got a good answer for you.

Just remember, to make a custom menu call you code, you simply put the
function name in the menus on-action setting.


=MyPrint()


or

=ShowPrinterDialog()

In your module called modPrint, you would place the two functions.

Public Function ShowPrinterDialog

On Error Resume Next
DoCmd.SelectObject acReport, Screen.ActiveReport.Name
DoCmd.RunCommand acCmdPrint

end function

Public Function MyPrint()

On Error Resume Next
Dim strReportName as string
strREportName = Screen.ActiveReport.Name
DoCmd.SelectObject acReport, strReportName
DoCmd.PrintOut acPrintAll

end function
 
G

Guest

Hi Van,
No, my module is named modGlobalCode and my function is fnPrint()

I did include the = sign before the function name on the property sheet for
the menu item.

Can you think of any other reasons why this wont work?

Dave
 
G

Guest

Hi Van,
I've managed to get it working. There wasn't a problem with the code or the
way I had set up the menu/command. I simply repaired the database and it
starting working exactly the way it should have before.
Strange...
I appreciate your help.
Thanks
Dave
 
G

Guest

Hold on...
the only way it will work is if I repair the database... Each time I close
out and come back into the db, it errors...

Dave
 
V

Van T. Dinh

It sounds like you have corruptions in your database.

Create a new blank database and import all objects (including MenuBar /
Toolbars) from the existing database.

If the above doesn't help, you can also try the /Decompile switch.
 
G

Guest

Van,
I tried importing everything to a blank db. It worked the first time, but
failed after that with the same error.

/decompile had the same results...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top