Basic VBA Question

  • Thread starter Thread starter S Jackson
  • Start date Start date
S

S Jackson

How do I tell the application to look and see what form it has open?

I want to tell it this:

If Forms!frmLTCRCases is Open Then . . .

Seems like a pretty basic question but I'm having trouble today --- its
Monday.

TIA
S. Jackson
 
Use the IsLoaded function that comes with the Northwind sample database.

1. Copy/paste this code to a new standard module so it can be used anywhere:

Public Function IsLoaded(ByVal strFormName As String) As Boolean
' 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

Compile the code, save/close the module as modIsLoadedFunction

2. Use code like this to check if a particular form is open:

If IsLoaded("frmLTCRCases") = True Then
' frmLTCRCases is open so do stuff here
Else
' frmLTCRCases is not open so do other stuff here
End If
 
How do I tell the application to look and see what form it has open?

I want to tell it this:

If Forms!frmLTCRCases is Open Then . . .

Seems like a pretty basic question but I'm having trouble today --- its
Monday.

TIA
S. Jackson

What version of Access?
Access 2002:
If Not CurrentProject.AllForms("frmLTCRCases").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 an event:
If Not IsLoaded("frmLTCRCases") Then
Do this
Else
Do that
End if
 
Back
Top