p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Access 2010 VBA Programmer's Reference (http://p2p.wrox.com/book-access-2010-vba-programmers-reference-597/)
-   -   Is the dialog form still loaded? (http://p2p.wrox.com/book-access-2010-vba-programmers-reference/85797-dialog-form-still-loaded.html)

esharris November 24th, 2011 07:25 AM

Is the dialog form still loaded?
 
I am using Access 2010.
Some form A opens form B in dialog mode. When A gets control back from the call, B is either loaded or unloaded. If (and only if) B is loaded, A can access to the fields within B. How can A determine if B is loaded? [:confused:]
The no-brainer solution is to create a public variable (outside of B) that B can set and A can read. But, passing data through a global variable tightens the coupling between A and B. Instead of becoming a reusable, custom dialog box, B becomes anchored to A through the global variable.
Is there an IsLoaded(Form) Boolean function that can make the determination? Then, B can us IsForm(A) to make the determination.
Is there a way to get form B to propagate an error to A? The error would indicate that the form is no longer loaded. Then, A can handle the error from B. I was unable to get that to work. See below.
Is there a way A can pass a call by reference parameter to B? Then, A can provide an out parameter to B. Openargs lets you pass a string by value?
Here is what nappen when I tried the error propagation proposal.
If form B raises an error in Form_Close, control doesn’t resume at the A’s error handler.
In the VB Editor, under Tools->Options->General, the error trapping is set to “Break on Unhandled Errors”.
In the call stack, the Form_Open call is under the Form_Close subroutine making the raise call.
It behaves like the error is unhandled. But the caller has an error handler. I tested the handling mechanism by raising an error directly in Form_Open. The handler does function.

Harry November 28th, 2011 09:37 AM

You may use a code like this
Code:

Function Isopen(formname As String) as Boolean
   
    Dim f As Form
    Isopen = False
    For Each f In Forms
        If formname = f.Name Then
            Isopen = True
            Exit For
        End If
    Next f
    Exit Function

This function returns True if the form is open, else it returns False.

Good luck


All times are GMT -4. The time now is 09:06 AM.

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