if form is open then...

lala

Registered User.
Local time
Today, 07:10
Joined
Mar 20, 2002
Messages
741
how can i say in code

if forms!jjj is open then
forms!kkk!kkk.requery
end if


how do i do this? how do i say IF THE FORM IS OPEN
 
Code:
If CurrentProject.AllForms("fFormName").IsLoaded Then
...

-dK
 
If you're using Access 2000 or earlier you need to call a function to return true or false when the form is open or not.

Include the following in a code module.

Code:
Function IsLoaded(ByVal strFormName As String) As Boolean

  'Returns True if the specified form is open in Form view or Datasheet view.
    
    Const conObjStateClosed = 0
    Const conDesignView = 0
    
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
        If Forms(strFormName).CurrentView <> conDesignView Then
            IsLoaded = True
        End If
    End If
    
End Function

Then, use something like...

Code:
If IsLoaded("yourFormNameHere") then
   'whatever when form is open
Else
   'whatever when form is closed
End if

Edit: From memory, later versions of Access include the Isloaded property whereas earlier versions didn't.
 
damn guys, how do ya know so much
not once have i not gotten an answer here
 
hehehe

I personally use something very similar Craig's offering especially if more than one instance when I need to check the form's status.

Also, heed his warning on the version (I forgot to mention).

-dK
 
my version is 2003 and 2007, i got both
but how does that work with multiple form instances? because that's my case, i want to check for few forms
i was just going to make few IF statements

i'm sure there's a better way, if you got time, can you explain?
 
I forgot about using the built-in property in newer versions until I was reminded by your post, dkinley. So between us we covered the bases :)
 
but how does that work with multiple form instances?

Not sure what you mean here. A particular form can only be open, or closed. You can several different forms open at the same time though?

Or do you mean in a multi-user environment?

Generally, with a multi-user database you have all the tables in one database object, called the backend. The forms/code etc are all in a separate database object, called the front end, which are linked to the backend data. Each user gets their own copy of the front end (so 10 users = 10 frontend copies) but each front end copy gets data from the same source (the one and only copy of the back end).

So, if you have this kind of setup (called a split database), the code in the frontend copy only has to deal with a single instance of any given form (the one inside the specific user's frontend copy).

AFAIK, there's no way to test if the form is open in another user's frontend unless you start putting some kind of data flag in a lookup table in the backend when the form is opened and removing that flag when it is closed.

But someone much clever than I might know a better solution.
 
If by multiple instances of form, you mean a user has two identical copy of same form open at same time on his end because you have something like this:

Code:
Dim frm1 As New Form_MyForm
Dim frm2 As New Form_MyForm

frm1.Visible=True
frm2.Visible=True

Then you need to use hWnd property to differentiate between the two instances.
 
Not sure what you mean here. A particular form can only be open, or closed. You can several different forms open at the same time though?.

no, sorry, i meant what dk said before
I personally use something very similar Craig's offering especially if more than one instance when I need to check the form's status.

lololol sorry, i remembered he said INSTANCES, English is not my language

anyway, nice guess banana, but no, it's much simpler
 
my version is 2003 and 2007, i got both
but how does that work with multiple form instances? because that's my case, i want to check for few forms
i was just going to make few IF statements

i'm sure there's a better way, if you got time, can you explain?

this is what i have now

Code:
If CurrentProject.AllForms("fprojectS").IsLoaded Then
[Forms]![fprojectS]![Status].Requery
[Forms]![fprojectS]![StatusL].Requery
End If
    If CurrentProject.AllForms("freportsanalyst").IsLoaded Then
    [Forms]![freportsanalyst]![Status].Requery
    [Forms]![freportsanalyst]![StatusL].Requery
    [Forms]![freportsanalyst]![PROJECTS.Status].Requery
    [Forms]![freportsanalyst]![PROJECTS.StatusL].Requery
    End If


so what was dk talking about in reference to this?
 
Ah, well then, what I think was meant is that he uses the same approach as I posted if there are many occassions within his database where he will want to test if forms are open.

It's just a little bit easier/faster to write...

If Isloaded("formname") then...

than it is to write

If CurrentProject.AllForms("fFormName").IsLoaded Then

every time you want to do such a check.

If you do a lot of these checks in your code, it's probably worth setting up the function and saving yourself some time later on. If you're using a later version of Access, like you are, then I think it's purely a matter of personal preference which method you choose.
 
ohhh, i copy and paste
very lazy )))))))))))))))))))))

but i like the first one better anyway

another question
how do i setup a function?

if you don't have the time to explain - it's not a problem
i like learning new things, that's why i keep asking more questions, but it's not an emergency
 
Well, you copy it, then paste it into a code module in the vba editor, and save the module (make sur ethe module has a different name than the function itself). Also, don't put functions that you might want to use throughout the database into a form's code module. Put it into a new Module that is not associated with a form, so that it can be accessed by code on other forms too. (Database window>Modules>New)


Then you can use it in your code.
 
ok, i understand all that
but copy what, the whole IF statement?

and how is it gonna help me if i still have to change the names of forms and fields everytime i use it

what am i missing?
 
ok, i understand all that
but copy what, the whole IF statement?

and how is it gonna help me if i still have to change the names of forms and fields everytime i use it

what am i missing?
The generic part of the function doesn't need a form name, you only add it from wherever you want to use so you only need to add the form name once
within this part
If Isloaded("formname") then...
 

Users who are viewing this thread

Back
Top Bottom