Looking for advice...."Cannot find form..."

Indigo

Registered User.
Local time
Today, 09:36
Joined
Nov 12, 2008
Messages
241
Good morning,

I am using Office 2016 and have several databases that I have used an auto-close method if idle based on this post:

http://www.utteraccess.com/forum/TimeOut-Forceoff-re-edit-t672964.html

When I open these databases, I have a main form and then a Hidden Security form that opens on the "OnOpen" event for the main form.

When the database times out and closes, I get a run time error 2450 MS Access cannot find the referenced form frmSecurity...

I can't seem to figure out how to prevent that error from appearing. I'm thinking it has something to do with the order of events on the forms as the database closes but haven't been able to get it to "resume next" and not appear.

Has anyone else ever come across this and can offer any advice? Much appreciated.
 
Did you put the time out code + timer in the security form? You should.
 
Oh, thank you Arnel... I didn't think of the timer...! But the problem is, I have a separate timer interval on the security form to determine the shift date. Our afternoon shift continues to run after midnight so I have a timer on the security form so that if the time is after midnight, to keep the previous day's date as the default date for data entry.
 
Add the function below to a standard module and call it just before you issue the Quit command to call it I use Call fCloseAll(Me.Name)

Code:
Function fCloseAll(Optional strForm As String)
Dim icount As Integer, intX As Integer
'strform is the form/report required to be left open while all
'else are closed.
icount = Application.Forms.Count - 1
    'close all forms
    For intX = icount To 0 Step -1
        If Forms(intX).Name <> strForm Then
            DoCmd.Close acForm, Forms(intX).Name
        End If
    Next
    
End Function

Cheers,
Vlad
 
Arnel has pointed you in the right direction, but the OTHER part of the solution is that if you are going to close things down, remember to force all timers to stop before you actually DO anything about closing the app. The surmise that it is an interaction between a form and a timer is probably right. It has been reported in this forum many times as causing Access to trip over a form that is closing but the timer wasn't stopped.
 
Just for coding kicks, I think the simplest way to close everything is this...
Code:
Sub CloseAll()
    Do While Forms.Count
        DoCmd.Close acForm, Forms(0).Name  [COLOR="Green"]'repeatedly close the 0th form in the collection[/COLOR]
    Loop
End Sub
...and if there is an exception, then we need a way to skip it in the loop...
Code:
Sub CloseAll(Optional Except As Access.Form)
    Dim i As Integer
        
    Do While Forms.Count - i
        If Except Is Forms(0) Then i = 1    [COLOR="green"]'if we encounter the exception, skip it[/COLOR]
        DoCmd.Close acForm, Forms(i).Name   [COLOR="green"]'close the 0th or 1st form, as the case may be[/COLOR]
    Loop
End Sub
Also, if we are not returning a value, we can use a Sub. Also note that we can pass in a reference to the Access.Form itself, not just the name. Either way.
Mark
 
Hello, I tried to put the code to close all forms into the database where the database prompts the user to close, but the same error message came up as well.
 
If you have a timer running, you need to reset it to zero before closing the form.

Before the DoCmd.Close operation, try a Forms(i).Timer = 0
 
I can't cause a form to fail to close because it has a timer running. That can't be the problem.
Mark
 
Mark, I have had mixed results with that issue. A fast enough timer can cause problems. Slow timers, not so bad. Which means it is a "timing window" issue, perhaps?
 
You say you put the call to close all forms where the database prompts the user to close. How do you prompt the user, with a message box? If the db is idle there is no user there to answer the prompt. You can use the attached objects to create the count-down timed prompt if you need one.

Have you tried to put the call (Call fCloseAll(Me.Name)) in the Form_Unload event of the main form that runs the idle timer?

Maybe you could upload a sample db so we could have a look.

Cheers,
Vlad
 

Attachments

can you not just hard code and specifically ignore an error with frmSecurity when closing the database?

Or maybe, when autoclosing, close frmSecurity first, then all the others.
 

Users who are viewing this thread

Back
Top Bottom