Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Location
    Chicago, IL
    Posts
    154

    Unanswered: How to tell if a form is open...

    Hello, ladies and gents...

    Is there a line that I can slap into a SQL query that says:

    IF FORM A is open THEN
    xyz = [forms]![form a]![auto number]
    else
    xyz = [forms]![form b]![auto number]
    end if

    I don't know how to query to see if a form is open!

    Thanks,

    mk

  2. #2
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Hi,

    A form is only in the Forms collection if it is open.
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  3. #3
    Join Date
    Feb 2004
    Posts
    533
    Usu. your not going to check for the form open in a query. You'd do this in a Sub Procedure. I use a version of the below function which can be found at http://www.mvps.org You'd call the function in your script ie.

    If fIsLoaded(Me.Name) Then
    ' Run my Query the form is Open
    Else
    ' Exit the form is not open
    Exit Sub
    End If

    Code:
    'http://www.mvps.org/access/forms/frm0002.htm
    
    '****** Code Start ********
    Function fIsLoaded(ByVal strFormName As String) As Integer
    'Returns a 0 if form is not open or a -1 if Open
        If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
            If Forms(strFormName).CurrentView <> 0 Then
                fIsLoaded = True
            End If
        End If
    End Function
    '****** Code End ********
    /
    ~

    Bill

  4. #4
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

  5. #5
    Join Date
    Feb 2004
    Posts
    533
    hammbakka, Thats the example that I recommended. Works good. One thing to point out about my previous post. You most likely would not use 'Me.Name' as the form name to check for open. Obviously form Me.name would be open as that is the form object of the form module. You would use the name of another form that you are interacting with.

    If fIsLoaded("frmFormNameToCheck") Then
    ' do something with the form
    Else
    'Exit
    Exit Sub
    End If



    .
    ~

    Bill

Posting Permissions

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