Hide X button on VBA forms

E

erin.sebastian

Hello All,
I am just wondering if it's possible at all to disable or hide the X
button on the top right hand corner of a word VBA windows form? The
form in question is a sub form of the main form in my application, I
want the user to be able to open the form, click off some options and
then close the form, when the form closes however (via the cmdbutton
close) it hides the form so that if they go back into it the options
they chose are still clicked off, if the user however clicks on the X
it disposes of the form and the options are gone.. so i don't want them
to be able to click the X at all...
Thanks in advance for your time!!
Erin
 
E

erin.sebastian

Hi All
I found a way to do it, via the Microsoft Word MVP site (which is a
great reference tool - http://word.mvps.org/FAQs/MacrosVBA/index.htm)
In the queryClose event of the userform you can put this code
If CloseMode = vbFormControlMenu Then Cancel = True
which will intercept the closing of the form and cancel it all
together.

Thanks,
Erin
 
J

Jonathan West

Hello All,
I am just wondering if it's possible at all to disable or hide the X
button on the top right hand corner of a word VBA windows form? The
form in question is a sub form of the main form in my application, I
want the user to be able to open the form, click off some options and
then close the form, when the form closes however (via the cmdbutton
close) it hides the form so that if they go back into it the options
they chose are still clicked off, if the user however clicks on the X
it disposes of the form and the options are gone.. so i don't want them
to be able to click the X at all...
Thanks in advance for your time!!
Erin

How to disable the X close button on a UserForm
http://word.mvps.org/FAQs/Userforms/DisableClose.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
Hi All
I found a way to do it, via the Microsoft Word MVP site (which is a
great reference tool - http://word.mvps.org/FAQs/MacrosVBA/index.htm)
In the queryClose event of the userform you can put this code
If CloseMode = vbFormControlMenu Then Cancel = True
which will intercept the closing of the form and cancel it all
together.


Make sure you tell the user what is going on, I would hate to click on the
X, expect the form to close, but instead, nothing happens, click again,
nothing again...
For example:

If CloseMode = vbFormControlMenu Then
MsgBox "You cant quit like that!"
Cancel = True
End If

Or tell them to use your own buttons instead.

Personally, I prefer to disable it, so visually, the user knows the X is not
functional.
See:
http://word.mvps.org/FAQs/Userforms/DisableClose.htm
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
K

Karl E. Peterson

I found a way to do it, via the Microsoft Word MVP site (which is a
great reference tool - http://word.mvps.org/FAQs/MacrosVBA/index.htm)
In the queryClose event of the userform you can put this code
If CloseMode = vbFormControlMenu Then Cancel = True
which will intercept the closing of the form and cancel it all
together.

That's a *great* technique. That is, *IF* you treat the [X] identical to
the "Cancel" button. No Cancel button? Disable instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top