Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Warwick, Warwickshire, England
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check if a form is already open using macro (2000)

    I have a macro which runs 4 reports. Each of the reports, when run individually starts by opening a form to allow the user to enter some criteria. Each report uses the same form (called imaginatively form1). In the macro which combines them, the form is displayed as each form opens. Is there macro condition which I can enter to check if the form is already open? If it is open I want skip the openform line in the macro.
    John

  2. #2
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check if a form is already open using macro (2000)

    Is the form (form1) closed when the first 'results' form is opened? if so why is the form closed after the first form has opened?

    Do the forms all run off queries pointed at form1? I'm guessing they do.

    If so, opening form1, requesting the criteria and then keeping form1 open in the background (minimised??) would allow the subsequent queries to get the criteria without repeatedly asking for it.

    I may be considering this too simplistically, but this is what I've done under similar circumstances.

    Ian

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Check if a form is already open using macro (2000)

    You can put the following function in a standard module:

    Function IsLoaded(ByVal strFormName As String) As Boolean
    ' Returns True if the form is loaded
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) Then
    IsLoaded = Forms(strFormName).CurrentView
    End If
    End Function

    Call it like this in code

    If IsLoaded("Form1") Then
    ...
    Else
    ...
    End If

    or use it as a condition in a macro.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Check if a form is already open using macro (2000)

    You can also use this in Access 2000 and 2002:

    <pre>If CurrentProject.AllForms(strFormName).IsLoaded = True then ...</pre>

    Charlotte

  5. #5
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Warwick, Warwickshire, England
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check if a form is already open using macro (2000)

    thanks all for your help - i've pieced together enough to sort the problem from your replies

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •