Results 1 to 9 of 9
  1. #1
    Star Lounger
    Join Date
    Apr 2002
    Location
    Onekama, Michigan, USA
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Report closing in run-time mode (A97SR2)

    I have created a run-time version and have reports that are generated when clicking a button. The report displays in print preview mode. The report has a custom menubar with two choices: print and close. When closing the report, either by clicking the "close" button of the "X" box in the upper right corner of the report print preview, the user is returned to the main menu. If the second "X" box in the far right upper corner is clicked, the complete program is shut down and the user is returned to the desktop. How can I disable the second "X" box?

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Report closing in run-time mode (A97SR2)

    I believe you are talking about the "x" that is part of the Access window itself. I don't think there is a way to diasable that. If you had a hidden form with code in its OnClose event, you might be able to Cancel the event if some conditions weren't met. For example, your usual Exit Application button might set a global field to Yes; so if that variable wasn't Yes, you'd know some other form of Exit was selected.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Report closing in run-time mode (A97SR2)

    The only way to disable the close button for the main window is through Windows API calls and the code is extremely ugly.
    Charlotte

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Report closing in run-time mode (A97SR2)

    Microsoft has a KB article on this: ACC2000: How to Disable the Close Button (X) on the Access Application Window (Q245746)

    I also found the following code in my collection. I didn't write it myself, but I don't know where I got it from (Calvin Smith?)
    To disable the close button of the Access application window, use

    SetControlBox False

    <img src=/w3timages/blueline.gif width=33% height=2>

    ' We need the following API declarations first

    Private Declare Function apiEnableMenuItem Lib "user32" Alias _
    "EnableMenuItem" _
    (ByVal hMenu As Long, _
    ByVal wIDEnableMenuItem As Long, _
    ByVal wEnable As Long) As Long

    Private Declare Function apiGetSystemMenu Lib "user32" Alias _
    "GetSystemMenu" _
    (ByVal hWnd As Long, _
    ByVal flag As Long) As Long

    Function SetControlBox(bEnable As Boolean, Optional ByVal lhWndTarget As Long = 0) As Long
    ' Purpose: disable or enable the control box of a form, report
    ' or the Access parent window.

    ' Arguments:
    ' bEnable: whether to disable or enable the control box.
    ' lhWndTarget (optional), for a window other then the Access parent window.

    ' Returns: 0 if disabled, 3 if enabled

    ' Example usage:
    ' lRetVal = SetControlBox(True) to enable -OR-
    ' lRetVal = SetControlBox(False) to disable

    ' NOTE: If no hWnd is passed in for a specific form, then the code
    ' assumes you want to enable/disable the close box of the Access app window

    Const MF_DISABLED = &H2&
    Const MF_ENABLED = &H0&
    Const MF_GRAYED = &H1&
    Const SC_CLOSE = &HF060&

    Dim lhWndMenu As Long
    Dim lReturnVal As Long
    Dim lAction As Long

    On Error GoTo ErrorHandling_Err

    lhWndMenu = apiGetSystemMenu(IIf(lhWndTarget = 0, _
    Application.hWndAccessApp, lhWndTarget), False)

    If lhWndMenu <> 0 Then
    If bEnable Then
    lAction = MF_ENABLED
    Else
    lAction = MF_DISABLED Or MF_GRAYED
    End If
    lReturnVal = apiEnableMenuItem(lhWndMenu, SC_CLOSE, lAction)
    End If

    SetControlBox = lReturnVal
    Exit Function
    ErrorHandling_Err:
    If Err Then
    ' Trap your error(s) here, if any!
    End If
    End Function

  5. #5
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Report closing in run-time mode (A97SR2)

    >>The only way to disable the close button for the main window is through Windows API calls and the code is extremely ugly.<<

    I suspected as much, but I figured it might be worth a shot to try to circumvent it.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  6. #6
    Star Lounger
    Join Date
    Apr 2002
    Location
    Onekama, Michigan, USA
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Report closing in run-time mode (A97SR2)

    Thank you for any and all help provided.

    First I must admit that I am not a programming guru.

    Attempted to duplicate the KB article (Q245746). Everything was accepted by the program but It did not return the desired results. Went through the Step-by-Step Example on a copy of my program and when starting the program, was presented with the following message box:


    (your program) can't find the name 'Function' you entered in the expression.

    You may have specified a control that wasn't on the current object without specifying the correct form or report context.

    To refer to a control on another form or report, precede the control name with the name of a collection, usually either Forms or Reports, and the name of the form or report to which the control belongs. For example, Forms![Products]![Units In Stock].


    Was this example designed for A2000 and does not work on A97?
    Was there an assumption of additional information that needs to be entered in order for the function to work?
    I don't know.

    Thanks again.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Report closing in run-time mode (A97SR2)

    The MSKB example for Access 97 looks the same to me as the 2000 example: Q258049.

    I tested the both the Microsoft code and the code in my previous reply in Access 97 and they work OK for me. I have attached an otherwise empty Access 97 database with the Microsoft code implemented.
    Attached Files Attached Files

  8. #8
    Star Lounger
    Join Date
    Apr 2002
    Location
    Onekama, Michigan, USA
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Report closing in run-time mode (A97SR2)

    It works just fine!
    Thank you very much for your assistance.
    You did it again.

    The malfunction was caused by the defect midway between my two ears. Under the Action Arguments I had typed: Function Name: InitApplication(). After removing the (Function Name it worked great.

    You may now proceed to ROFL.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Report closing in run-time mode (A97SR2)

    This kind of thing happens to all of us. You feel you're <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15> until somebody points out something that is obvious in retrospect.

    Regards,
    Hans

Posting Permissions

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