locked
How to close a MsbBox still open on screen although the database is shut down by code RRS feed

  • Question

  • Hi 

    I use an excellent code to shut down a database if there is no activity during an hour.

    First of all, your code works perfect. But there is one issue.

    In one special case, with a certain Form open, your code causes problem. Or maybe its more right to say that the OnUnload Property on that specific Form causes the problem.

    On OnUnload there is a macro with a reminder to the user (in this case a brewer) to update "stock balance". This event is fired when your code shut down the database but the remiding MsgBox remains on screen although the database is shut down.
    Is there a way to shutdown also MsgBoxes like this?

    The code is like this (Thanks to Chris Ward)

    1. Timer Interval set to 60000
    2. On Timer with the following procedure
    Private Sub Form_Timer()
             Const IDLEMINUTES = 60
    
             Static PrevControlName As String
             Static PrevFormName As String
             Static ExpiredTime
    
             Dim ActiveFormName As String
             Dim ActiveControlName As String
             Dim ExpiredMinutes
    
             On Error Resume Next
    
             ActiveFormName = Screen.ActiveForm.Name
             If Err Then
                ActiveFormName = "No Active Form"
                Err = 0
             End If
    
             ActiveControlName = Screen.ActiveControl.Name
                If Err Then
                ActiveControlName = "No Active Control"
                Err = 0
             End If
    
             If (PrevControlName = "") Or (PrevFormName = "") _
               Or (ActiveFormName <> PrevFormName) _
               Or (ActiveControlName <> PrevControlName) Then
                PrevControlName = ActiveControlName
                PrevFormName = ActiveFormName
                ExpiredTime = 0
             Else
                ExpiredTime = ExpiredTime + Me.TimerInterval
             End If
    
             ExpiredMinutes = (ExpiredTime / 1000) / 60
             If ExpiredMinutes >= IDLEMINUTES Then
                ExpiredTime = 0
                IdleTimeDetected ExpiredMinutes
             End If
    
    End Sub

    Followed by the following sub

    Sub IdleTimeDetected(ExpiredMinutes)
       With Screen.ActiveForm
          If Screen.ActiveForm.Dirty = True Then
          .Undo
          End If
          End With
       Application.Quit
    End Sub


    Best // Peter Forss Stockholm and Sigtuna GMT +1.00

    Thursday, February 25, 2016 3:14 PM

Answers

  • Hi Peter,

    To workaround the message box, we can try other way to kill the Access process instead of using "Application.Quit".

    Here is a demo for your reference:

      Dim Process As Object
        For Each Process In GetObject("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name = 'msaccess.exe'")
            Process.Terminate
        Next
    
    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by ForssPeterNova Friday, February 26, 2016 5:18 AM
    Friday, February 26, 2016 2:58 AM
  • Just found that the locking file not disappear when the FE database is Terminated by the code:

    Hi Peter,

    As long as you can delete the locking file by hand, there should be no problem.

    But instead of using the MsgBox, can you use a home-made message form? That should be removed on Application.Quit.

    Imb.

    Friday, March 4, 2016 8:19 AM

All replies

  • Hi Peter. This may not be the solution but if there's only one form causing this issue and you know which one it is, then perhaps you could address that specific form in your shutdown code. Just my 2 cents...
    Thursday, February 25, 2016 5:52 PM
  • Hi Peter,

    To workaround the message box, we can try other way to kill the Access process instead of using "Application.Quit".

    Here is a demo for your reference:

      Dim Process As Object
        For Each Process In GetObject("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name = 'msaccess.exe'")
            Process.Terminate
        Next
    
    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by ForssPeterNova Friday, February 26, 2016 5:18 AM
    Friday, February 26, 2016 2:58 AM
  • Thank you R&F

    It works very well


    Best // Peter Forss Stockholm and Sigtuna GMT +1.00

    Friday, February 26, 2016 5:19 AM
  • Hi

    Just found that the locking file not disappear when the FE database is Terminated by the code:

    Dim Process As Object
        For Each Process In GetObject("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name = 'msaccess.exe'")
            Process.Terminate
        Next



    Best // Peter Forss Stockholm and Sigtuna GMT +1.00


    Friday, March 4, 2016 6:27 AM
  • Just found that the locking file not disappear when the FE database is Terminated by the code:

    Hi Peter,

    As long as you can delete the locking file by hand, there should be no problem.

    But instead of using the MsgBox, can you use a home-made message form? That should be removed on Application.Quit.

    Imb.

    Friday, March 4, 2016 8:19 AM
  • Hi Peter. As Imb said, try using the Kill command to manually delete the lock file. I like his suggestion of using a form as a message box if possible. Just my 2 cents...
    Friday, March 4, 2016 5:36 PM
  • Hi Peter. As Imb said, try using the Kill command to manually delete the lock file. I like his suggestion of using a form as a message box if possible. Just my 2 cents...

    Hi DB guy,

    The Kill command is not exctly what I meant. The Kill command is from within Access, and on that moment probably the locking file is still "owned" by the Access process.

    But when you quit Access, and you can manually delete the locking file, there was no ownership anymore. On the other hand, when you cannot delete the locking file, then there is still an Access process running.

    Imb.

    Friday, March 4, 2016 6:19 PM
  • Hi Imb. Sorry for the confusion. I thought the OP has a separate instance of Access trying to shutdown another. Thanks for the clarification. Cheers!

    I really think if the OP knows which form is causing the problem, then it would be an easier approach to check if it is open. If so, disable the MsgBox before quitting the application.

    Just my 2 cents...

    Friday, March 4, 2016 7:49 PM
  • Hi Imb and DB

    I have decided to use home-made message forms. It seems to be a clean and reliable solution.

    Best // Peter Forss Stockholm and Sigtuna GMT +1.00

    Sunday, March 6, 2016 2:53 PM
  • I have decided to use home-made message forms. It seems to be a clean and reliable solution.

    Hi Peter,

    You are talking about message formS. But you only need one.

    You can make a Sub Show_message (msg_txt as String). Within this Sub you open your Msg_form, whereby the message itself is passed to the Msg_form using the OpenArgs argument.

    Wherever you need a message, you just run:      Show_message "This message is to inform you ..."

    Lateron you can add a second parameter to nuanciate for the kind of message form.

    Imb.

    Sunday, March 6, 2016 8:15 PM
  • Hi Peter. Glad to hear you found a working solution. Good luck with your project.

    Sunday, March 6, 2016 10:27 PM