Solved

Disable Close Option on MDI Parent, Enable on Child

Posted on 2002-03-15
13
296 Views
Last Modified: 2010-05-02
I'm trying to make a menu editor that functions similar to the way that MS Office apps do.  I have a File/Close menu option in the MDI application, but I can't figure out how to code it.  

If the user clicks close (or uses the shortcut) I want to close the MDI child that has focus.  And, I want the close option to be disabled if the MDI parent is the only thing open.

Right now, the close option is enabled on all forms (both parent and child).  Also, if I put an Unload Me in the Click event of mnuClose, the MDI parent unloads, thereby unloading the application - rather than unloading the child form that has focus.
0
Comment
Question by:cnealy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 

Expert Comment

by:bill02
ID: 6869462
all you need is this code


Unload ActiveForm

or if its on a button thats not on the mdi form then

unload MDIForm.Activeform

that should do it
0
 
LVL 1

Author Comment

by:cnealy
ID: 6869472
Great!  Unload ActiveForm Worked.

Now ... how do I disable the Close menu option if the MDI parent is the only form that's loaded?
0
 
LVL 1

Author Comment

by:cnealy
ID: 6869477
Great!  Unload ActiveForm Worked.

Now ... how do I disable the Close menu option if the MDI parent is the only form that's loaded?
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Expert Comment

by:bill02
ID: 6869493
If ActiveForm Is Nothing Then
disable button
End If
that should be all you need to do
0
 
LVL 1

Author Comment

by:cnealy
ID: 6869503
Where do I put the code?
0
 
LVL 1

Author Comment

by:cnealy
ID: 6878208
Bill - when you explain where to put the code, I can accept your answer.  
0
 

Expert Comment

by:bill02
ID: 6878671
when do you want the button to be unabled you could put them on child form close you could put them on form load form initialize when do you want it to become enabled put the code there
0
 
LVL 1

Author Comment

by:cnealy
ID: 6878783
I want the close button to be enabled only when the MDI parent is the only form that is loaded.  So, I'm still unclear on where to put it.   I tried putting it in the MDI Parent's Activate event, but that event only fires once when the application is initially loaded.

Any details (code examples)  you can provide would be great.

Thanks.
0
 

Accepted Solution

by:
bill02 earned 50 total points
ID: 6878846
on child form unload
button.enabled = false
on child forms gotfocus
button.enabled = true
on mdiform load
If ActiveForm Is Nothing Then
button.enabled = false
End If
this is the easiest way there is another that im not to sure of thats the link mode on mdi and child forms you could set the links and when a link closes check to see if activeform but im not sure how that works
0
 
LVL 1

Author Comment

by:cnealy
ID: 6878883
Does this mean that I'll need to code Unload and GotFocus events on every child form one by one?  I have about 25 forms, so this will take awhile.  Can you think of any other way that I can determine if the MDI parent form is the only form that's open?  Unfortunately, I don't see a GotFocus event for the MDI parent ....
0
 
LVL 1

Author Comment

by:cnealy
ID: 6878886
Does this mean that I'll need to code Unload and GotFocus events on every child form one by one?  I have about 25 forms, so this will take awhile.  Can you think of any other way that I can determine if the MDI parent form is the only form that's open?  Unfortunately, I don't see a GotFocus event for the MDI parent ....
0
 

Expert Comment

by:bill02
ID: 6878895
yes i know that is the problem i was running into to see if the mdi form has focus im not sure how to obtain that the only way i know how to do it is put it on every form
0
 
LVL 1

Author Comment

by:cnealy
ID: 6878918
Thanks, Bill02.  
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question