Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 24th, 2006, 03:38 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Yorba Linda, California, USA.
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Default determine if an invisibile form is open

How can I determine if a form is open or not?

I have a form that I have made invisible, so I can use it as a datasource to populate another form. When I am done with it, I have to close it. But I only want to close it if it is open, so I don't get an error.

I've tried:
1) if isloaded(frmName) then.... (and it's not a function, so it errors)
2) if forms!frmName.isloaded = true then .... (and it errors, and when I went to help is said available for Data Access Page)

Is there another property I can look at?

Thank you,

Loralee



Reply With Quote
  #2 (permalink)  
Old February 24th, 2006, 04:15 PM
Friend of Wrox
 
Join Date: Dec 2005
Location: , , .
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I believe this question was answered a few weeks ago, you might be able to find it by looking back. If not however, you could attach events to the form's OnOpen and OnClose events to set a variable that would keep track of its current state.

Reply With Quote
  #3 (permalink)  
Old February 24th, 2006, 05:45 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

loralee,

There is a forms collection. For each form in your application, it is given an index number when opened.

How do you want to check to see if the form is open?

Kevin

dartcoach
Reply With Quote
  #4 (permalink)  
Old February 24th, 2006, 05:55 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Loralee,

Here's the code:

Dim frm as form
For I = Application.Forms.Count to 1 step - 1
  If Forms(I -1).name = (yourformnamehere)
     docmd.close acform, forms(I-1).name
  end if
next I

How and where you want to execute this is up to you.

Kevin

dartcoach
Reply With Quote
  #5 (permalink)  
Old February 24th, 2006, 05:57 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Yorba Linda, California, USA.
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Default

KEvin,
I was hoping to use something more permanent to the individual form, such as the name of the form and a property I could check......

All I want to do is confirm the form is open so I can close it, without scoring an error for closing something that is not open.

I've looked through the history on the Forum for the past several weeks and do not find any topic remotely matching this.

Thanks,
Loralee

Reply With Quote
  #6 (permalink)  
Old February 24th, 2006, 06:01 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Loralee,
Does your application open forms on top of each other? When do you need to check to see if its open?

Kevin

dartcoach
Reply With Quote
  #7 (permalink)  
Old February 24th, 2006, 06:28 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Yorba Linda, California, USA.
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks Kevin,
I'll give it a try. My reply was meant to reply to your 1:55 post. (I was posting to Steve on another question.......Sorry)

My app DOES open some forms on top of each other.
This part is checking to see if ptis already known, and if not, adding pt. There is more than one "que" the user can take to get to the form the way I have it set up now, so I've got to determine if it is open before I try closing.....

Thanks,

Loralee

Reply With Quote
  #8 (permalink)  
Old February 24th, 2006, 08:25 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Sounds like your looking for the tried and true IsLoaded function. Here are three versions I've stored away over the years. Each takes a single form name as a parameter and is called with:

Code:
If IsLoaded("frmYourForm") Then
  Form!frmYourForm.Cloase  
End If
VERSION ONE:

Code:
Function IsLoaded(ByVal strFormName As String) As Integer
' Returns True if the specified form is open in Form view or Datasheet view.
 
' These variables are used to test the return values of the SysCmd function
'  and the CurrentView property of the requested form.
    Const conObjStateClosed = 0
    Const conDesignView = 0

    'The first If statement uses the SysCmd function to check the current
    'state of the requested form. It can be in one of four states: not open
    'or nonexistent, open, new, or changed but not saved.
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then

        'The second If statement checks for the current view of the requested
        'form, assuming the previous If statement found it to be open. If
        'the form is currently open in Form View, the function will return
        'true. If the form is in Design View, the function will return false.
        If Forms(strFormName).CurrentView <> conDesignView Then
            IsLoaded = True
        End If

    End If

End Function
VERSION TWO (much like one):

Code:
Function IsLoaded(ByVal strFormName As String) As Integer
    Const CLOSED = 0
    Const DESIGN = 0

    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> CLOSED Then
        If Forms(strFormName).CurrentView <> DESIGN Then
            IsLoaded = True
        End If
    End If
End Function
VERSION THREE:

Code:
Function IsLoaded(ByVal strFormName As String) As Boolean
 ' Returns True if the specified form is open in Form view or Datasheet view.
    Dim oAccessObject As AccessObject

    Set oAccessObject = CurrentProject.AllForms(strFormName)
    If oAccessObject.IsLoaded Then
        If oAccessObject.CurrentView <> acCurViewDesign Then
            IsLoaded = True
        End If
    End If

End Function
HTH,

Bob

Reply With Quote
  #9 (permalink)  
Old February 24th, 2006, 08:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Actually version one and two are identical, just different constant names. Anyway, pass the name of your hidden form (which is open in Form view, just hidden) to the function, and it will true (-1).

Bob

Reply With Quote
  #10 (permalink)  
Old February 24th, 2006, 08:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

 
Quote:
quote: if isloaded(frmName) then.... (and it's not a function, so it errors)


Came across this comment. Didn't see it earlier (just checking e-mail).

IsLoaded is a user-defined function, not an intrinsic VBA function. If you simply call it, without having it defined some where, yes, you'll get an error. My previous post provides three user-defined definitions of IsLoaded, one of which is typically placed in a standard module.

Bob

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open one form or the other mean34dean Access VBA 4 August 21st, 2008 12:02 PM
Close all MdiChield form from open one form/Button salman .NET Framework 2.0 6 December 10th, 2007 03:21 AM
Close all MdiChield form from open one form salman .NET Framework 1.x 0 November 8th, 2007 12:32 AM
Open Form, run query, open form Grafixx01 Access 7 April 26th, 2007 11:32 AM
Determine if a form is open Danton Access VBA 1 October 7th, 2004 04:59 PM



All times are GMT -4. The time now is 11:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.