Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Question Unanswered: Preventing prints in Access: Possible to block or redirect CTRL+P keystroke in forms?

    By combining the following:

    - setting page borders to 130mm on top, bottom, and 100mmm left and right (A4 page setup), a printout withoug adjusting the margins gives around a 1cm print on each page, which discourages any printout of the particular form...
    , and

    - using dialog borders for the form

    plus

    - having the form open as a fixed pop-up that stays on top and blocks access to other db windows/menus/toolbars
    ( this is also an mde...)

    , I am close to preventing printouts for particular forms, for example preventing anybody from printing the customer list, etc.

    BUT: in a pop-up window, even if you manage to block the above, CTRL+P still works. I get somewhat around that by adjusting the margins, but that is not an elegant solution.

    Is it possible to block/disable/capture/redirec the CTRL+P shortcutkey in Access only, without affecting other Apps?

    But if anyone knows a "real" solution to block printing from selected forms in Access (2003), that is what I really want...

    D.

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    In the Events tab of your Form's properties window, set the Key Preview property to Yes.

    Now, in the Key Down event of your Form, enter the following code:

    If (Shift And acCtrlMask) > 0 And KeyCode = 80 Then KeyCode = 0

    Ctrl-P no longer works for your form.


  3. #3
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    Originally posted by CyberLynx
    In the Events tab of your Form's properties window, set the Key Preview property to Yes.

    Now, in the Key Down event of your Form, enter the following code:

    If (Shift And acCtrlMask) > 0 And KeyCode = 80 Then KeyCode = 0

    Ctrl-P no longer works for your form.

    Excellent! Seems to be just what I hoped was possible, will try it asap :-)

    D.

  4. #4
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Lightbulb Tip to prevent access to certain print functions

    Solution to prevent access to page setup, print previev
    and the Print... menu options on the default File menu.
    (relevant for MDE front-ends where one cannot use custom
    menus/custom toolbars):

    Modal: Yes
    Pop-up: Yes
    Border style: Dialog

    This way it is also possible to use
    - DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
    - DoCmd.RunCommand acCmdFind
    within VBA code for search buttons on the form, even if
    the menus are not available.

    Note/Tip:
    If you open a form such as the above using Dialog Border
    style through a Macro that opens the form, DO NOT set the
    macro to open the form as a dialog as well. Set the macro
    to open the form as "normal", and have the dialog setting
    in the form's properties. If you specify dialog in both
    "ends", you won't be able to access the search window from
    this pop-up/modal form.

    Still not giving up on initial questions:
    1. I am still curious about what I initially asked about:
    Can I trap the menu options of (the events of) page setup,
    print preview and print... - and redirect or cancel them
    using VBA? (Havent given Cyberlynx' advice about disabling CTRL+P a try yet, and have not given it a thought of whether there are possibilities within that area to limit the menu options in the first place... Very interested in comments/tips on this).

    2. Any other way to search all the content of the
    recordset, and place only the resulting record on the
    form, not letting users access (but still see the search results there)
    the form while in the search window, OR having the search function only display a recordset with one record at the time while searching
    through the whole underlying recordset..? I may have to
    make a search window of my own? I would need the
    functionality where one can see the resulting record
    without closing the search window, hence be able to
    continue searching if the current result is not the
    desired one.

    D.

  5. #5
    Join Date
    Nov 2003
    Posts
    1,487
    For item 1:

    Create your own menu(s) and apply them when required via your Form's Menu Bar property:

    Me.MenuBar = "myMenuName"



    For item 2:

    Progmaticly set your search criteria into the Form's Filter Property then in the same instance, set your Form's Record Locks property to All Records.


  6. #6
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Question

    Originally posted by CyberLynx
    For item 1:
    Create your own menu(s) and apply them when required via your Form's Menu Bar property:
    Me.MenuBar = "myMenuName"

    For item 2:
    Progmaticly set your search criteria into the Form's Filter Property then in the same instance, set your Form's Record Locks property to All Records.
    ok, but:
    1. When using MDE I am not sure if that option of using custom menus/bars is available, will test it.
    2. This is a multi-user db, cannot lock all records at ANY time from anywhere... What exactly would that do for the solution to no. 2, though? It is not obvious to me what relevance it would have to limit the possibility to access the records in the form while in the search window?

    BTW: Thanks very much for the CTRL+P advice, works perfect :-)

    D.

  7. #7
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    1. it is!

    izy
    currently using SS 2008R2

  8. #8
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    hmmm, only the Alt+Printscreen combination can be controlled within Access, so a block of PrintScreen itself must at least be something like "while the db is open" , even if the db windows do not have focus, can that be done? More a windows problem than a db problem, though. Guess this is not the place to ask this particular question.

    D.
    Last edited by kedaniel; 04-08-04 at 14:37.

  9. #9
    Join Date
    Aug 2004
    Posts
    1
    If you want to disable (or replace) any pre-defined shortcut key combo (such as ctr-P) you can do this by creating a Macro and calling it AutoKeys and in the "Macro Name" column use enter the shortcut key you wish to replace for example Ctrl-P becomes ^P (the SHIFT key is + and other keys are enclosed in brackets like {DEL} look in the SendKeys Help file for key combo syntax) - if you are disabling a shortcut key, then create the AutoKeys macro, enable the Maro Name column and enter your shortcut key but leave the Action colum blank

    This method has one drawback / benefit - when you create the AutoKeys macro, it will have this functionality globally throughout your project. You may find this to be a plus, if you want all of your forms to not be printable, but this means your reports would not be CTRL-P printable from the Print Preview mode, but most people use the Menu bar anyways, and if you are creating a "redistributable" application with "Office Developers Tools", then you will have to be sure the Print icon button is on the menu bar, but since disabling CTRL-P does not completely cut off any possibility of printing, it is still a viable solution to this problem
    Last edited by rolaaus; 08-10-04 at 22:12.

  10. #10
    Join Date
    Aug 2013
    Posts
    1

    My Somewhat Convoluted Solution

    I realize this post is quite old, but I managed to find it in my search for an answer, so I feel like I might as well post my solution.

    I spent a long time trying to find a more refined method of controlling the use of Ctrl+P on specific reports, but unfortunately, I wasn't able to find the ideal kind of method that I would have liked. I believe I could have had a better solution with Access 2010, which gave reports the Key Press event, and I will be migrating to that soon, but I haven't done so yet.

    Nonetheless, I have managed to get a solution that is acceptable. This is my solution. First, I removed all normal printing toolbars by opening the report in dialog mode. Second, I put the "^P" macro name in the AutoKeys macro. I then assigned this to "RunCode" and specified a function to run. Here's the code I created for the function:

    Code:
    Function PickAPrinter() 
    On Error Resume Next 'if you close the dialog once it opens it throws an error message otherwise
          If Not StopPrint Then
                  FocusCodeOnCurObj 
                  DoCmd****nCommand acCmdPrint 
          End If
    End Function
    Code:
    Function FocusCodeOnCurObj()
    On Error GoTo TheEnd
            If Reports.Count > 0 Then
                   DoCmd.SelectObject acReport, Screen.ActiveReport.Name 'puts focus on the appropriate thing in the case in which the timer running on main form manages to take the focus to itself
            ElseIf Forms.Count > 0 Then
                   DoCmd.SelectObject acForm, Screen.ActiveForm.Name
            End If
    Exit Function
    TheEnd:
            If Err.Number = 2475 Then DoCmd.SelectObject acTable, Screen.ActiveDatasheet.Name 'unfortunately, there is not Datasheets.count, so this is the best I know to do
            Resume Next
    End Function
    The only other thing I had to do was to set the "StopPrint" variable, which I declared at a module level, to True prior to opening my report and to false after closing it.

  11. #11
    Join Date
    Nov 2009
    Posts
    9
    Quote Originally Posted by CyberLynx View Post
    In the Events tab of your Form's properties window, set the Key Preview property to Yes.

    Now, in the Key Down event of your Form, enter the following code:

    If (Shift And acCtrlMask) > 0 And KeyCode = 80 Then KeyCode = 0

    Ctrl-P no longer works for your form.

    Thanks, Very good solution

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •