yhwhlivesinme
asked on
Trap Printing in form view
I have some users who were trained before to press ctrl-p to print out their reports because the toolbars were restricted. Now occasionally (about once a month) a user hit's ctrl-p in a form and prints out like 100 pages, is there a way to trap the printing in a form?
ASKER
so if I add a button to the form that's a print button, it will execute if the user hit's ctrl p?
(1) Add a button, and give it a name that makes sense, like cmd_print, btn_print, etc.
(2) In the button's Caption event type &Print
(3) Type VBA code in the button's .Click event that performs a printing-like task (DoCmd.Report "Some Report Name", acViewNormal, ...)
Then, when the user selects {Ctrl} + P, the code in (3) will execute, just as if the user clicked on the button.
Hope this helps.
-Jim
(2) In the button's Caption event type &Print
(3) Type VBA code in the button's .Click event that performs a printing-like task (DoCmd.Report "Some Report Name", acViewNormal, ...)
Then, when the user selects {Ctrl} + P, the code in (3) will execute, just as if the user clicked on the button.
Hope this helps.
-Jim
ASKER
what's the caption event type? do you mean just caption? I'm using acc 97 btw
ASKER
I added a button, in the caption I added &Print, and then in the onclick event I put a messagebox, but it doesn't execute it!
That is because Access has captured the Print. remove the Print Option from the Menu (customize).
Or add a KeyPress event handler to the form and cancel the keypress if it is Ctrl P
Or add a KeyPress event handler to the form and cancel the keypress if it is Ctrl P
ASKER
keypress event wont work (yes I did try it) because another control cant have the focus, the form must have the focus, but you can press ctrl-p anytime.
ASKER
I just tried adding a custom toolbar as well and that doesn't work. I also tried creating a new form and just adding a button on that (for simplicity) and it didn't work either. Let me walk you through the steps so you can see if I'm doing anything wrong
create a button
change it's caption to &print
create an onclick event for this button in vb
create a button
change it's caption to &print
create an onclick event for this button in vb
Remove Print from the Access built-in File menu - othewise you will get 2 controls trying to use the same accelerator key - better yet - go to options and disable built-in menus and keyboard short-cuts
ASKER
I want to leave keyboard shortcuts on for other forms, and I want users to be able to use ctrl-v and ctrl-c for copy and paste, I did remove print from the access built in file menu
ASKER
I removed the print button from the file menu, I changed the toolbar to a custom toolbar and it still isn't working
ASKER
raised points to 500, didn't know it was going to be this difficult
If you made your caption &Print - the key combination to make it run is Alt + P
To have Ctrl + P capture - create a custom menu Item and assign Ctrl + P as the keyboard shortcut
To have Ctrl + P capture - create a custom menu Item and assign Ctrl + P as the keyboard shortcut
I just realized that I led you astray; &P is actually {alt} + P as andrewbleakley states.
I think Ctrl - P is Microsoft application-wide default for print, and prints whatever is active, whether it ends up being 1 page or 100. I'm not entirely certain you can override this.
Sorry for the confusion.
-Jim
I think Ctrl - P is Microsoft application-wide default for print, and prints whatever is active, whether it ends up being 1 page or 100. I'm not entirely certain you can override this.
Sorry for the confusion.
-Jim
ASKER
Thanks Jim, I believe you are right, I tried what andrew said, and it doesn't seem to be working
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Boag, Nice!!! thanks a lot, that worked great!
A couple of questions, that didn't disable the use of ctrl-v and ctrl-c to copy and paste did it (I think I tested it and it still works - which is what I want).
Is there a way to put in the conditions of that macro if the active object is a form or report? because I would (Ideally) like users to be able to press ctrl-p to print reports.
A couple of questions, that didn't disable the use of ctrl-v and ctrl-c to copy and paste did it (I think I tested it and it still works - which is what I want).
Is there a way to put in the conditions of that macro if the active object is a form or report? because I would (Ideally) like users to be able to press ctrl-p to print reports.
ASKER
I've used this before to determine if an object is open, can I do it for all forms?
SysCmd(acSysCmdGetObjectSt ate, acForm, "frmDlySummaryRptInfo")
or is there another way to determine if the active object is a form or not?
SysCmd(acSysCmdGetObjectSt
or is there another way to determine if the active object is a form or not?
ASKER
nevermind, this is what I did, (for completion sake) in the conditions of the macro that I created I put a function name, here's the function:
Function currObject() As Boolean
If Application.CurrentObjectT ype = 3 Then
currObject = True
Else
currObject = False
End If
End Function
Application.CurrentObjectT ype will return the following:
acTable (0) The active object is a table.
acQuery (1) The active object is a query.
acForm (2) The active object is a form.
acReport (3) The active object is a report.
acMacro (4) The active object is a macro.
acModule (5) The active object is a module.
acDataAccessPage (6) The active object is a data access page.
acServerView (7) The active object is a server view.
acDiagram (8) The active object is a database diagram.
acStoredProcedure (9) The active object is a stored procedure.
then in the action part of the query I put printout so that it only prints out if the active object is a report!
Thanks for all the help!
Function currObject() As Boolean
If Application.CurrentObjectT
currObject = True
Else
currObject = False
End If
End Function
Application.CurrentObjectT
acTable (0) The active object is a table.
acQuery (1) The active object is a query.
acForm (2) The active object is a form.
acReport (3) The active object is a report.
acMacro (4) The active object is a macro.
acModule (5) The active object is a module.
acDataAccessPage (6) The active object is a data access page.
acServerView (7) The active object is a server view.
acDiagram (8) The active object is a database diagram.
acStoredProcedure (9) The active object is a stored procedure.
then in the action part of the query I put printout so that it only prints out if the active object is a report!
Thanks for all the help!
yhwhlivesinme,
I see you have been very busy!
:)
If you had made another macro:
^c
Yes, that would have disabled the Copy command.
Similarly:
^v
Would have disabled Paste.
Also note: This will disable the commands in the "Access" environment only. They will still work in the Visual Basic Editor.
I only use this to "Totally" disable a command.
What I found is that many users became confused as to when Ctrl-C would work and when it would not.
And what if they had a Report and Form open at the same time! Most users don't know what "The Focus" of an "Active Object" means!
:)
But I am impressed with your "Macro" (If you could call it that now!)
:)
But anyway....
Glad I could help!
I see you have been very busy!
:)
If you had made another macro:
^c
Yes, that would have disabled the Copy command.
Similarly:
^v
Would have disabled Paste.
Also note: This will disable the commands in the "Access" environment only. They will still work in the Visual Basic Editor.
I only use this to "Totally" disable a command.
What I found is that many users became confused as to when Ctrl-C would work and when it would not.
And what if they had a Report and Form open at the same time! Most users don't know what "The Focus" of an "Active Object" means!
:)
But I am impressed with your "Macro" (If you could call it that now!)
:)
But anyway....
Glad I could help!
In many applications, a form will have a Print button (with .Click event code) with a caption of &Print. This means that if the user hits {Ctrl} + P, then the code behind the Print button's .Click event.