Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to check form if open 2

Status
Not open for further replies.

Madiba1

Programmer
Apr 18, 2006
15
A2
Good morning am writing an application which need to check if the preceeding forms are open. If they are closed user should not proceed using the current form.
SOS pls
 
How are ya Madiba1 . . .

In a module in the modules window, copy/paste the following function:
Code:
[blue]Function IsOpenForm(frmName As String) As Boolean
   Dim cp As CurrentProject, Frms As Object
   
   Set cp = CurrentProject()
   Set Frms = cp.AllForms
   
   If Frms.Item(frmName).IsLoaded Then
      If Forms(frmName).CurrentView > 0 Then IsOpenForm = True
   End If
   
   Set Frms = Nothing
   Set cp = Nothing

End Function[/blue]
To use the function:
Code:
[blue]   If IsOpenForm("[purple][b]YourFormName[/b][/purple]") Then
      [green]'Code if open[/green]
   Else
      [green]'Code if closed[/green]
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
I tend to use SysCmd like so:
Code:
'There are four states you can check for:
'acObjStateOpen - open
'acObjStateNew - new
'acObjStateDirty - changed but not saved
'0 (zero) - closed or non-existant
 If SysCmd(acSysCmdGetObjectState, acForm, "YourFormName") = acObjStateOpen Then 
...
So no need to write your own function.

[pc2]
 
. . . and if the form is open in design view?

Calvin.gif
See Ya! . . . . . .
 
Why would you care about the form being open in design view if you're writing code to prevent the user from proceeding? Seems to me, you would not allow the user to open a form in design view.



Randy
 
How are ya randy700 & mp9 . . .

I agree [blue]design view[/blue] is not a part of normal operations, however, during [blue]design & testing[/blue] of several DB's I'd get an error because I left one open. It was easy enough to take care of this in code.

[purple]Those errors will never bother me again![/purple] ;-)

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top