Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If a form is open close on open of another form 2

Status
Not open for further replies.

RachelK

Programmer
Mar 18, 2002
171
0
0
GB
Hi,

I have had a dig around on the net and I can't seem to find what I am looking for.

I have a form called "CourseProviders" that is open most of the time however I have another form called "frmStudent", upon open of the "frmStudent" form I would like to check the form "frmCourseProviders" is not open and close the "frmCourseProviders" if it is open .

I don't know how go about this any sugestions I would be greatfull. Thanks Rachel
 
Hi Rachel,

this function will let you check and see if a form is open already;

Code:
Function fIsLoaded(ByVal strFormName As String) As Boolean
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
        If Forms(strFormName).CurrentView <> 0 Then
            fIsLoaded = True
        End If
    End If
End Function

you can then simply use an if statement to check like so;

Code:
If fIsLoaded("frmCourseProviders") Then
    DoCmd.Close acForm, "frmCourseProviders"
End If

That should do what you need.

Sim

----------------------------------------
My doctor says that I have a malformed public duty gland and a natural deficiency in moral fibre and that I'm therefore excused from saving universes.
----------------------------------------
 
Sounds like there was a race going on. Anyway I am just starting out so excuse me if I ask stupid questions. The function is that a gobal function that I can call at anytime? Cheers Rachel
 
It is indeed, place it in a module then you can call it like a built in function. Its code that gets used over and over in a couple of my applications making it a prime function candidate.

----------------------------------------
My doctor says that I have a malformed public duty gland and a natural deficiency in moral fibre and that I'm therefore excused from saving universes.
----------------------------------------
 
Mute,

It was a global function I there in end. Anyway it worked fantastically. Cheers for your help. Rachel
 
There is another way to check to see if a form is open (feature added to Access 2000).
Code:
    If (CurrentProject.AllForms("frmCourseProviders").IsLoaded) Then
    DoCmd.Close acForm, "frmCourseProviders"
 
There is a FASQ that check if an other form is loaded. Also you could write a query on a tomer tat checks if the form has been loaded since (run ever 10 seconds) :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top