Strange problem closing Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bigukfan
    New Member
    • Mar 2010
    • 21

    Strange problem closing Access

    I have an application using multiple Forms, all unbound. The main Form enables users to select which other Forms they want to use, only one at a time, all Modal. I don't want users to close Access via the red Close X top right, only from the main menu Form, which records certain data when closing.

    To achieve this, I declared a public variable at Form level in the main 'menu' Form:

    Code:
    Public fOKClose As Boolean
    Obviously this is False by default, and only when the main Form is closed via a Command Button is it set to True first. In the main Form, the code in the Unload event is:

    Code:
    If fOKClose = False Then Cancel = True
    Now this works fine when only the main Form is open. However, if a second Form is open and the user clicks the application close x top right, the code does work, the application does not close BUT I can not close the second (Modal) Form by clicking the Close Command Button. I set the close Command Button's Cancel property to True, so pressing the Esc key does close the Form, but I don't understand why this is the case. There is a TextBox in one of the Forms opened after the main Form, and when the user clicks the X top right, despite subsequently clicking the Close Command Button to no effect, it is still possible to type in the TextBox, so the Form must have focus.

    I have tried using DoCmd.CancelEve nt rather then Cancel = True, to no avail. Any ideas as to what is going on would be welcome.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32653

    #2
    Originally posted by BigUKFan
    BigUKFan:
    BUT I can not close the second (Modal) Form by clicking the Close Command Button.
    Is this only after trying to close the Application using the Application's red X? Does it work normally (if this hasn't already been attempted)?

    Comment

    • bigukfan
      New Member
      • Mar 2010
      • 21

      #3
      Yep, application closes when user clicks Close Command Button on the main Form, and application does not close if only main Form open and user tries to close it with the red X top right, but does then close if user then clicks the Close Command Button. The problem starts when a second Form is opened.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32653

        #4
        OK. Your clarification doesn't fill me with confidence as you go into detail in a separate scenario.

        What exactly happens when the second (modal) form is up and the Close Command Button is pressed. There are two possible scenarios here :
        1. Normal use - No Application Close requested yet.
        2. After Application Close (Red X) has been attempted.


        It could be that you've stumbled across a bit of an anomaly, but I don't want to go there or explore it (a fair amount of work) until I'm clear there is no misunderstandin g here.

        Comment

        • dsatino
          Contributor
          • May 2010
          • 393

          #5
          You might want to just hide the application's title bar. This way they can't close it until they close the modal form to get to the button you gave them.

          Comment

          • bigukfan
            New Member
            • Mar 2010
            • 21

            #6
            NeoPa - in answer to your questions:
            1 When Close Command button clicked on second Form Form closes, no problem
            2 After Application Close has been attempted, user clicks Close button, nothing happens (however, pressing Esc closes Form)

            dsatino - Not sure how to hide Application title bar, and had not thought of this either. Any advice?

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32653

              #7
              Originally posted by BigUKFan
              BigUKFan:
              2 After Application Close has been attempted, user clicks Close button, nothing happens (however, pressing Esc closes Form)
              In that case I think you may have a strange one there. I don't understand what may be causing this, but it certainly seems illogical. If you'd like to post a copy of your database I could have a look at it for you. I'll copy some instructions below that I've used before for indicating how best to prepare for posting a copy of your database.

              When attaching your work please follow the following steps first :
              1. Remove anything not relevant to the problem. This is not necessary in all circumstances but some databases can be very bulky and some things do not effect the actual problem at all.
              2. Likewise, not entirely necessary in all cases, but consider saving your database in a version not later than 2003 as many of our experts don't use Access 2007. Largely they don't want to, but some also don't have access to it. Personally I will wait until I'm forced to before using it.
              3. If the process depends on any linked tables then make local copies in your database to replace the linked tables.
              4. If the database includes any code, ensure that all modules are set to Option Explicit (See Require Variable Declaration).
              5. If you've done anything in steps 1 to 4 then make sure that the problem you're experiencing is still evident in the updated version.
              6. Compile the database (From the Visual Basic Editor select Debug / Compile {Project Name}).
              7. Compact the database (Tools / Database Utilities / Compact and Repair Database...).
              8. Compress the database into a ZIP file.
              9. When posting, scroll down the page and select Manage Attachments (Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.) and add this new ZIP file.

              It's also a good idea to include some instructions that enable us to find the issue you'd like help with. Maybe some instructions of what to select, click on, enter etc that ensures we'll see what you see and have the same problems.

              Comment

              • bigukfan
                New Member
                • Mar 2010
                • 21

                #8
                OK desatino, I found an API that hides the Application Toolbar, which negates the need for my code. It does not answer the question about why this was happening in the first place, but as NeoPa pointed out, this may be an issue with the OS. Thanks for the help.

                Comment

                Working...