 |
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 24th, 2006, 03:38 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|

February 24th, 2006, 04:15 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

February 24th, 2006, 05:45 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|

February 24th, 2006, 05:55 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|

February 24th, 2006, 05:57 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|

February 24th, 2006, 06:01 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Loralee,
Does your application open forms on top of each other? When do you need to check to see if its open?
Kevin
dartcoach
|
|

February 24th, 2006, 06:28 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|

February 24th, 2006, 08:25 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
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
|
|

February 24th, 2006, 08:36 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
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
|
|

February 24th, 2006, 08:44 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
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
|
|
 |