Is a particular form Open or not (1 Viewer)

Raabi

Registered User.
Local time
Today, 22:07
Joined
May 19, 2008
Messages
21
Good day everybody

I am making good progress in my project with the help of you geeks. Presently, I am facing couple of problems as below.

I want to know; if a particular form, "frmViewEdit" for example, is open or not. If a user tries opening a Child-form, it should see the Parent-form status and if that is not open, the user is to be prompted for opening the Master-form instead of the Child-form.

Also, I could not find a way to maximize the Database window, programmatically. Some of my forms are aligned with the right side of the window. When the database window is maximised, these forms appear ok, otherwise right-hand side of them is obscured unless I resize the database window.

I am expecting help as always.
 

ajetrumpet

Banned
Local time
Today, 13:07
Joined
Jun 22, 2007
Messages
5,638
I want to know; if a particular form, "frmViewEdit" for example, is open or not
You do that like this:
Code:
On Your Event()

  If SysCmd(acSysCmdGetObjectState, acForm, "FormName") <> _
      conObjStateClosed then
    MsgBox "The form is Open (Loaded)"
  Else
    MsgBox "The form is Closed"
  End If
Also, I could not find a way to maximize the Database window, programmatically.
You can write an "AutoExec" macro for your database, and the DB window will maximize on open:
Code:
docmd.maximize
Or, to use a macro action, use "Maximize".
 

Raabi

Registered User.
Local time
Today, 22:07
Joined
May 19, 2008
Messages
21
Thanks for the help, Ajutrumpet. But, the constant conObjStateClosed does not seem working. However, if that is replaced by acObjStateOpen, it is all right.

I just wonder, if there can be a simpler (more digestable :)) solution for finding the form status, as well.
 

Raabi

Registered User.
Local time
Today, 22:07
Joined
May 19, 2008
Messages
21
Sorry, I have another problem with testing the form status. Please refer to my following code:

Private Sub Form_Open(Cancel As Integer)
Dim Msg As String

Msg = "Please Open the 'frmViewEdit' Master-form to view this."
If SysCmd(acSysCmdGetObjectState, acForm, "frmViewEdit") <> _
acObjStateOpen Then
MsgBox Msg, vbExclamation, "It is a Child form"
Cancel = 1
End If
End Sub

In this case, Cancel = 1 does not close the Cild form. Further help is requested.
 

DCrake

Remembered
Local time
Today, 19:07
Joined
Jun 8, 2005
Messages
8,632
Simple Software Solutions

Place this function in a module

Code:
Public Function IsLoaded(strFormName As String) As Boolean
'Purpose :To check wether a given form is loaded or not
'        :When referring to forms by name, the form must be open or access returns an error

    Dim i As Integer
    For i = 0 To Forms.Count - 1
        If (Forms(i).Name = strFormName) Then
            IsLoaded = True
            Exit For
        End If
    Next
End Function

How to call this function:

On an event procedure use the following syntax:

Code:
If IsLoaded("frmViewEdit") Then
   your code here....
Else
   your code here....
End If

CodeMaster::cool:
 

Raabi

Registered User.
Local time
Today, 22:07
Joined
May 19, 2008
Messages
21
Yah! this is much easeir to understand and to remember. Thanks DCrake for the tip.
 

Users who are viewing this thread

Top Bottom