Testing for an active form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

I have some code which tests for the name of an active form (i.e.
Screen.ActiveForm.Name). If there is no active form, an error occurs which at
the moment I have to use error handling to deal with.

Is there a way I can test if there is a form active, rather than relying on
error handling?

Many thanks

David
 
Hi all

I have some code which tests for the name of an active form (i.e.
Screen.ActiveForm.Name). If there is no active form, an error occurs which at
the moment I have to use error handling to deal with.

Is there a way I can test if there is a form active, rather than relying on
error handling?

Many thanks

David

What version of Access?
Access 2002:
If Not CurrentProject.AllForms("FormA").IsLoaded Then
Do something here
Else
Do something else
End If

In Access 97, copy this function (from the Northwind.mdb sample
database) into a Module.

Function IsLoaded(ByVal strFormName As String) As Integer
' Returns True if the specified form is open in Form view or
Datasheet view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function
==============

Then code:
If Not IsLoaded("FormA") Then
Do this
Else
Do that
End if
 
Hi Fred

Thanks for your response.

I'm using 2003. Sorry, I didn't make my question clear. I want to be able to
test if any form is active, not a specific form. I.E. is the active database
object a form?

Thanks

David
 
David Cleave said:
Hi all

I have some code which tests for the name of an active form (i.e.
Screen.ActiveForm.Name). If there is no active form, an error occurs
which at the moment I have to use error handling to deal with.

Is there a way I can test if there is a form active, rather than
relying on error handling?

If Forms.Count > 0 Then
' There's at least one form open.
Else
' There isn't.
End If
 
Hi David,

What's wrong with error handling? E.g. (needs testing):


Public Function IsAFormActive() As Boolean

Dim frmF As Access.Form
Dim lngErr As Long

On Error Resume Next
Set frmF = Screen.ActiveForm
lngErr = Err.Number
Set frmF = Nothing
On Error GoTo 0

Select Case lngErr
Case 0
IsAFormActive = True
Case 2475
IsAFormActive = False
Case Else
'unexpected error
IsAFormActive = False
Err.Raise lngErr, , "Unexpected error in IsAFormActive"
End Select

End Function
 
Back
Top