• Report closing in run-time mode (A97SR2)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Report closing in run-time mode (A97SR2)

    Author
    Topic
    #373486

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #600549

      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.

      • #600654

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

        • #600699

          >>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.

    • #600676

      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

      ‘ 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

      • #600750

        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.

        • #600756

          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.

          • #600779

            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.

            • #600785

              This kind of thing happens to all of us. You feel you’re brickwall until somebody points out something that is obvious in retrospect.

              Regards,
              Hans

    Viewing 1 reply thread
    Reply To: Report closing in run-time mode (A97SR2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: