Results 1 to 7 of 7
  1. #1
    wdrspens is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    35

    Test if Form is Open

    Is there a way to test whether or not a form is open?
    I would like to use code to close another form which may or may not be open. I can use the On Error Resume Next to avoid the code stopping and asking to be debugged, but I would prefer simply to test whether it is open and close it only if it is open.

  2. #2
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    What if you used a global boolean variable? When the specific form opens set the variable to True, and when it closes set it to false.

  3. #3
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274

  4. #4
    wdrspens is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    35
    Thank you for the suggestions. Also the discussion on dbformums was very interesting. I have plenty to be going on with.
    Meanwhile how do I set a global boolean variable?
    Thanks

  5. #5
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Within any Module at the very top of your code - underneath your "Option Compare Database and "Option Explicit" (If you have added it) and before your first function.

    Code:
    Option Compare Database
    Option Explicit
    Global gblFormOpen as Boolean
    
    Function funFirstFunction()
    'Function Code
    End Function

  6. #6
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    How about simply:

    Code:
    If CurrentProject.AllForms.IsLoaded("FormNameHere") Then
       DoCmd.Close acForm, "FormnameHere", acSaveNo
    End If

  7. #7
    wdrspens is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    35
    Thanks, I have adopted the If currentproject aproach, and so far it is working.
    Many thanks all

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Test Library Design
    By P5C768 in forum Database Design
    Replies: 1
    Last Post: 09-27-2010, 05:14 PM
  2. Test data for queries
    By nacho in forum Queries
    Replies: 6
    Last Post: 04-16-2010, 11:01 PM
  3. Keying in Test answers to Access DB from Written Test
    By CityOfKalamazoo in forum Access
    Replies: 3
    Last Post: 03-01-2010, 08:58 AM
  4. Replies: 2
    Last Post: 02-26-2010, 08:14 AM
  5. Replies: 0
    Last Post: 12-01-2008, 03:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums