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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If Visible then Enabled

Status
Not open for further replies.

mettodog

Vendor
Jul 11, 2000
94
US
certain menu's should only be enabled when a form is visible, when the form is not visible, the menu items should not be enabled. right now i have this code placed on frmNoteTemplate
formmain.mnucloseitem.Enabled = True
formmain.mnusaveitem.Enabled = True
formmain.mnusaveasitem.Enabled = True
formmain.mnucompileitem.Enabled = True
formmain.mnuundoitem.Enabled = True
formmain.mnucutitem.Enabled = True
formmain.mnucutitem.Enabled = True
formmain.mnucopyitem.Enabled = True
formmain.mnupasteitem.Enabled = True
formmain.mnuassignnameitem.Enabled = True

that works fine except when you close that form, the menu items are still enabled. How do i make it so that they are not enabled when frmNoteTemplate is not visible?
 
Hey there,....

Try using in the Form_Unload

Menuname.Enabled = False

Or am I missing the point..?

krkX
 
i have never used the Form_Unload event before. how do i use it?
 
You should already have you code placed in the Form_Load event. Which means that when the form is loaded (note that this does not necessarily mean visible), then the code you have will be executed.
Similarly, when the form is unloaded the Form_Unload event will trigger and any code in that event will be executed.

For example:

Option Explicit

Private Sub Form_Load

'enable menu items
formmain.mnucloseitem.Enabled = True
formmain.mnusaveitem.Enabled = True
formmain.mnusaveasitem.Enabled = True
formmain.mnucompileitem.Enabled = True
formmain.mnuundoitem.Enabled = True
formmain.mnucutitem.Enabled = True
formmain.mnucutitem.Enabled = True
formmain.mnucopyitem.Enabled = True
formmain.mnupasteitem.Enabled = True
formmain.mnuassignnameitem.Enabled = True

End Sub

Private Sub Form_Unload

'disable menu items
formmain.mnucloseitem.Enabled = False
formmain.mnusaveitem.Enabled = False
formmain.mnusaveasitem.Enabled = False
formmain.mnucompileitem.Enabled = False
formmain.mnuundoitem.Enabled = False
formmain.mnucutitem.Enabled = False
formmain.mnucutitem.Enabled = False
formmain.mnucopyitem.Enabled = False
formmain.mnupasteitem.Enabled = False
formmain.mnuassignnameitem.Enabled = False

End Sub


Simon
 
when i run the program, i get a compile error, it says

procedure declaration does not match description of event or procedure having the same name
 
thanks for your help, i got it to work. i just added some code to trap the "X" click procedure, and placed the code in there.
 
OK - the procedure declarations should look like this:

Private Sub Form_Load()

End Sub

Private Sub Form_Unload(Cancel As Integer)

End Sub


with the same code as above inside each procedure.

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top