Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2003
    Posts
    42

    Unanswered: How to test if a form is open?

    Hiya,

    Been searching thru the help files and had no luck with this...

    What I need to do...

    There are 2 forms: A and B

    On form A the user can add extra records to the DB.

    Form B has a listbox which displays a list of these records.

    Form B is not always going to be open when Form A is open...

    In the Form A code, I added a requery of the listbox on Form B... but it crashes unless Form B is open.

    ie.

    Form!FormB!lstListBox.requery

    How can I test that FormB is open, so that this requery is only done when FormB is open so it does not crash?

    Or, am I taking the wrong approach?

    Many thanks in advance...

    Ventelation.

  2. #2
    Join Date
    Dec 2002
    Location
    Glasgow, UK
    Posts
    100
    If you are using access 2k or above you can use the currentproject method:

    if currentproject.allforms("Form B").isloaded then
    formb.listbox.requery
    end if

    hope this helps

  3. #3
    Join Date
    Jan 2003
    Location
    Aberdeen, Scotland, UK
    Posts
    168
    If you are on 97 you can use the following in a module:

    Function IsOpen(StrName As String, Optional intObjectType As Integer = acForm)
    IsOpen = (SysCmd(acSysCmdGetObjectState, intObjectType, StrName) <> 0)
    End Function

    then you can just use:

    if isopen("FrmWhatever") then DoSomething.
    J.

  4. #4
    Join Date
    Apr 2003
    Posts
    42

    Thanks

    Thanks....

    In the meantime I set up a global module with global Boolean 'flag' variables that I turn on and off depending on whether the form is open or not. And then use these variables on the other forms to test if the form is open.

    ie.
    On form_open
    flagFormAOpen = True
    End Sub

    On form_close
    flagFormAOpen = False
    End Sub

    etc.

    It works. But may give the suggested functions a go. Less messy code, and less commenting.

  5. #5
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    the first thig I always do (i am extremely "old school") is copy the isloaded function from the northwind db in 97

    if isloaded ("myfromname") then

    whatever

    else

    whatever

    end if

  6. #6
    Join Date
    May 2003
    Location
    Bucharest
    Posts
    16

    Re: How to test if a form is open?

    i think that you taking the wrong approach?

    why do you need to requery the listbox if the form is not open???

    you have to put the requery event on open for form B and on activate on form B.

    in this way when you want to use the list on form be it will be allways with the latest data.
    Theodor

  7. #7
    Join Date
    Apr 2003
    Posts
    42

    Thanks...

    I did not think to use 'On Activate'.

    I was attempting to use Form 'Got Focus' for the Requery but did not work... I've never used 'On Activate' before... Yay! Now I know what it does and that's what I was originally trying to fix the prob with.

    Thanks for the 'If form is open' test code, also... I'm sure I'll need that at some stage anyway.

    I think I'll revise my VB texts and study up on my form "Event Properties".

    Cheers!

  8. #8
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    a good practice technique is tearing apart the northwinds sample database and reading the code

    also
    If in 2000 create macros and convert the macros to code - you can learn alot this way

    But DO NOT use the macros in your app - no error handling


    Litwin's Access developers handbook series are a must

Posting Permissions

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