Problem checking if form is open

  • Thread starter Thread starter Max Moor
  • Start date Start date
M

Max Moor

Hi All,

I have a function to test if a form is open or not. I didn't write it,
nor do I know where it came from. The function is (with the error handler
removed):

Public Function FormIsLoaded(ByVal strFormName As String) As Boolean
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
If Forms(strFormName).CurrentView <> 0 Then
FormIsLoaded = True
End If
End If
End Function

I call this to see if a form "frmLeftNav" is open. I know for a fact
that it is not open.

SysCmd(acSysCmdGetObjectState, acForm, strFormName) returns a 1,
though, saying it is open. Of course, the Forms(strFormName).CurrentView
part then throws an error, because the form isn't open.

Does anyone understand the acSysCmdGetObjectState well enough to tell
me what might be wrong?

Regards,
Max
 
Iterate through the Forms collection to see what's really open, e.g.:
? Forms.Count
? Forms(0).Name
and so on.

If the database is in an inconsistent state, a compact/repair may help. If
you need more than that, see:
Recovery sequence - Standard steps to recover a database
at:
http://allenbrowne.com/recover.html
The SaveAsText would be worthwhile if the previous steps don't do it.

The best way to test if a form is open any version from A2000 on is:
? CurrentProject.AllForms(strFormName).IsLoaded

Let us know if you are still stuck.
 
CurrentProject.AllForms(strFormName).IsLoaded

Hi Allen,

A compact and repair did fix the problem. Nonetheless, I've updated my
FormIsLoaded and ReportIsLoaded functions to call the AllForms or AllReports
collections, as you selected.

I've said it before, though I've lost count with you... Thank you for
the help!

Regards,
Max
 
Back
Top