Run Queries on Close of DB without Form ???!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • isetea
    New Member
    • Sep 2006
    • 44

    Run Queries on Close of DB without Form ???!!!

    Hi,
    I want to have some queries run on close of my database like the function "Repair on Close" But I don't want to use a form with VBA code or command buttons doing it. Is there any other possibility ??!!
    Thanks in advance for answers :)
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    I don't believe there is a way - I've had a look around, but I'll watch this thread with interest in case someone finds a way.
    Very interesting question BTW.

    Comment

    • Andrew Thackray
      New Member
      • Oct 2006
      • 76

      #3
      There is no direct way. However this is a workaround that has the same effect

      1 - create a blank form
      2 - In its on Unload event run the code you want to execute when the database closes.
      3 - set the forms visible properties to False so it is invisible
      4 - create an autoexec macro that opens the form invisibly when the database opens.

      If you do this closing the database will unload the hidden form and trigger the code you want to execute when the database closes.

      Comment

      • isetea
        New Member
        • Sep 2006
        • 44

        #4
        Hi Andrew,
        that's really a good indirect way :) I have just one question. User can close the database pressing the little x-button on the screen. They actually always do it, if the database doesn't have a form exiting the application. Are you sure that hitting this little x will run the unload event in the hidden form? I ask because I tried something like that already and it didn't seem to workmout. But maybe I missed something and made it wrong...?


        Originally posted by Andrew Thackray
        There is no direct way. However this is a workaround that has the same effect

        1 - create a blank form
        2 - In its on Unload event run the code you want to execute when the database closes.
        3 - set the forms visible properties to False so it is invisible
        4 - create an autoexec macro that opens the form invisibly when the database opens.

        If you do this closing the database will unload the hidden form and trigger the code you want to execute when the database closes.

        Comment

        • isetea
          New Member
          • Sep 2006
          • 44

          #5
          Forget my last post. IT IS WORKING :) :) :)
          The only thing is I can't get the form invisible there is no such a property. I will try with a new form...Maybe that helps!
          But thanks for your great help!
          Ciao

          Originally posted by isetea
          Hi Andrew,
          that's really a good indirect way :) I have just one question. User can close the database pressing the little x-button on the screen. They actually always do it, if the database doesn't have a form exiting the application. Are you sure that hitting this little x will run the unload event in the hidden form? I ask because I tried something like that already and it didn't seem to workmout. But maybe I missed something and made it wrong...?

          Comment

          • Andrew Thackray
            New Member
            • Oct 2006
            • 76

            #6
            Originally posted by isetea
            Forget my last post. IT IS WORKING :) :) :)
            The only thing is I can't get the form invisible there is no such a property. I will try with a new form...Maybe that helps!
            But thanks for your great help!
            Ciao
            Glad it works.

            I forgot, you cant't set a forms visible property but you can use the HIDE method on it.

            You can load to form invisibly with the followig code line

            Forms("Myform") .hide.

            This loads the form but makes it not visible to the user

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              This is a funny one.

              You can't set the .Visible property directly - instead you call the .Hide() & .Show() methods of the form.
              Code:
              Call Form_frmDummy.Hide()

              Comment

              • isetea
                New Member
                • Sep 2006
                • 44

                #8
                I don't have a comand like "hide" in my libraries. Do I need somethig special. My code is now:

                Private Sub Form_Load()
                Forms("frm_not_ close").hide
                End Sub

                And not working...


                Originally posted by Andrew Thackray
                Glad it works.

                I forgot, you cant't set a forms visible property but you can use the HIDE method on it.

                You can load to form invisibly with the followig code line

                Forms("Myform") .hide.

                This loads the form but makes it not visible to the user

                Comment

                • isetea
                  New Member
                  • Sep 2006
                  • 44

                  #9
                  Can you give me maybe the full code? I'm not really that professional with VBA. Just started...
                  :)

                  Originally posted by NeoPa
                  This is a funny one.

                  You can't set the .Visible property directly - instead you call the .Hide() & .Show() methods of the form.
                  Code:
                  Call Form_frmDummy.Hide()

                  Comment

                  • Andrew Thackray
                    New Member
                    • Oct 2006
                    • 76

                    #10
                    I tried the Hide command on a form but it also didn't work

                    However putting this line in the forms Open event did work

                    me.visible = false

                    It seems that although you can't see the visible property in a forms properties sheet, you can still reference id it VBA.

                    Comment

                    • isetea
                      New Member
                      • Sep 2006
                      • 44

                      #11
                      Hm. It's not working. The only code I have in the form is the following:

                      Private Sub Form_Open(Cance l As Integer)
                      Me.Visible = False
                      End Sub

                      Private Sub Form_Unload(Can cel As Integer)
                      DoCmd.RunMacro "mcr_001_Run_Ma ke_Table_Querie s"
                      End Sub

                      Still the form is visible when I open the database. Any suggestion?

                      Originally posted by Andrew Thackray
                      I tried the Hide command on a form but it also didn't work

                      However putting this line in the forms Open event did work

                      me.visible = false

                      It seems that although you can't see the visible property in a forms properties sheet, you can still reference id it VBA.

                      Comment

                      • Andrew Thackray
                        New Member
                        • Oct 2006
                        • 76

                        #12
                        I put the me.visible line in the form_load event.

                        However this is wierd. I tested the code by inserting it in an existing form in design view & then clicking the form view button. Lo & Behold the form dissapears.

                        However if I call the same form from a swithchboard entry it does not disappear !!

                        If i step through the code the form duly disappears as the me.visible = false is executed but promptly re-appears when the on load or on open routines terminate. Acces itself must set the visible property to true as part of the load & open events after the code is executed

                        However I put the line in the Form_Activate event and this seems to work

                        the code is as follows

                        Private Sub Form_Activate()

                        Me.Visible = False

                        End Sub

                        Comment

                        • PEB
                          Recognized Expert Top Contributor
                          • Aug 2006
                          • 1418

                          #13
                          And PLS 1 question?

                          Do you have a Switchboard in your datbase? Why don't you do it Modal... So when you close the database as you want it will be the last one to close in fact i fyou've setup to not appear the database window of course!

                          And on form close you can express what to happen! :)

                          Comment

                          • isetea
                            New Member
                            • Sep 2006
                            • 44

                            #14
                            Yeah PEB, i wished this would be the situation. Actually I can't persuade the user to have his database running with a nice fancy switchboard. The user is more down-to-earth. So no from no switchboard and the possibility that the user closes the database with the little cross in the upper right side of his screen :)

                            But I try the me.visible on Activate and if this does not help the user will have a little picture somewhere, which is the form.

                            Thanks to everybody :) :)

                            Originally posted by PEB
                            And PLS 1 question?

                            Do you have a Switchboard in your datbase? Why don't you do it Modal... So when you close the database as you want it will be the last one to close in fact i fyou've setup to not appear the database window of course!

                            And on form close you can express what to happen! :)

                            Comment

                            Working...