We help IT Professionals succeed at work.

Disable Print Preview

stevensont
stevensont asked
on
611 Views
Last Modified: 2008-02-01
Experts:

I open all reports in Print Preview mode. However, when users select Print Preview from the menu bar or tool bar, the report closes. I would like to know how to disable Print Preview on the menu and tool bars when a report is opened in that mode and turn it on again when the report is closed by the user.

Thanks.
Comment
Watch Question

Commented:
You can programatically turn the menus or menu items off.  If you would like code to turn off your menus let me know.  I don't see a Preview button in the Report toolbar?

Author

Commented:
YES...I posted the question for an example of the code. I also created a toolbar with the Print Preview.

Commented:
Save this in a public module and call it using:

SetEnabledState True    'or false

If you look at the ExitMenuState sub you can see how to disabe whatever you like.

****************************************

Option Compare Database
Option Explicit

Private Declare Function GetSystemMenu Lib "User32" (ByVal hwnd As Long, _
    ByVal bRevert As Long) As Long

Private Declare Function EnableMenuItem Lib "User32" (ByVal hMenu As _
    Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long

Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&

Public Function SetEnabledState(blnState As Boolean)
    Call CloseButtonState(blnState)
    Call ExitMenuState(blnState)
End Function

Sub ExitMenuState(blnExitState As Boolean)
'Disable File function
    Application.CommandBars("File").Enabled = blnExitState
'Disable Window function
    Application.CommandBars("Window").Enabled = blnExitState
'Disable Edit function
    Application.CommandBars("Edit").Enabled = blnExitState
'Disable Insert function
    Application.CommandBars("Insert").Enabled = blnExitState
'Disable Tools function
    Application.CommandBars("Tools").Enabled = blnExitState
'Disable Help function
    Application.CommandBars("Help").Enabled = blnExitState
'Disable Records function
    Application.CommandBars("Records").Enabled = blnExitState
'Disable View function
    Application.CommandBars("View").Enabled = blnExitState
'Can be changed to disable sub menus too:
    Application.CommandBars("File").Controls("Close").Enabled = blnExitState
'Disable Format function
    Application.CommandBars("Format").Enabled = blnExitState

   


End Sub

'Disable the Close Button Option
Sub CloseButtonState(boolClose As Boolean)
    Dim hwnd As Long
    Dim wFlags As Long
    Dim hMenu As Long
    Dim result As Long
       
    hwnd = Application.hWndAccessApp
    hMenu = GetSystemMenu(hwnd, 0)
    If Not boolClose Then
        wFlags = MF_BYCOMMAND Or MF_GRAYED
    Else
        wFlags = MF_BYCOMMAND And Not MF_GRAYED
    End If
   
    result = EnableMenuItem(hMenu, SC_CLOSE, wFlags)
End Sub


Author

Commented:
OK - Thanks. Give me a little time to test it.

Author

Commented:
I forgot all about this open question. I'll print it as a reminder and test it within a few days. Sorry about the wait.

Author

Commented:
This is good stuff, but it does not address my problem. Again, I would like to know how to disable the Print Review submenu option when a report is in Print Preview mode. Thanks!
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.