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

Disable the close button of a message box

Status
Not open for further replies.

mach27

Technical User
Oct 25, 2005
18
0
0
Hello experts

Is there a way to disable the "close button" of all the message boxes? If not possible, make it all not visible.

I've read other forums and I can't find any solution to what I want to do.

Cheers,
[glasses]
 
It is possible but involves some very complex code.

Why is it you want to achieve this?

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
make it all not visible
Like this ?
DoCmd.SetWarnings False

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi HarleyQuinn: I don't want the users to have an alternate way of closing a certain message box as doing it won't process some procedures.

Hi PHV: Where should I put the "DoCmd.SetWarnings False" ?

Cheers
[glasses]
 
Why not just have the close button act as a Cancel button as per standard office application behaviour?

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
Also, what button sets are you using for the message box? For example vbYesNo automatically disables the close button as there is no cancel option.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
Hi HarlyQuinn

I use the vbOKOnly most of the time as majority of the message box gives information to the users.

I will just change my button set to vbYesNo to disable the close button.

cheers,
[glasses]
 
The vbOKOnly option produces the same result (1, vbOK) regardless of if you click OK or close using the close button.

So, in theory, it shouldn't case any of you procedures to be missed?

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
Sorry, meant to post some code to illustrate that [blush]
Code:
Select Case MsgBox("Check me", vbOKOnly)
Case vbOK
    MsgBox "OK"
Case Else
    MsgBox "Not OK"
End Select

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
i think he means the close button on the top right. the X

i think...

Valgore
 
valgore said:
i think he means the close button on the top right. the X

I think so too, but disabling that button isn't straight forward (see here) and seems a pointless exercise.

If you're only showing the ok button (with vbOkOnly), then it doesn't matter whether they click the "x" or press ok. They've seen and acknowledged the message box. If you're asking a question (vbYesNo, etc) then just check for the affirmitive
Code:
if MsgBox("Do You Really Want To Hurt Me?",vbYesNo)=vbYes then
....
end if
and treat anything else (the no button, the cross) as the same thing.



----------------------------------------------
Ben O'Hara
David W. Fenton said:
We could be confused in exactly the same way, but confusion might be like Nulls, and not comparable.
 
well, couldnt you look at the property sheet for the form? from there you can disable the close button in Access 2007
 
valgore said:
i think he means the close button on the top right. the X
He does, if you try using a vbYesNo (or for that matter vbAbortRetryIgnore) msgbox the button is disabled.

If you use a vbOKOnly (as both Ben and I have said), the close button in the top right will produce the exact same result as the OK button (so nothing extra to check). Any msgbox that has a cancel option, the close button returns the same value as a Cancel being clicked.

Again, as both Ben and I have said, rather than trying to disable it (if the msgbox button set doesn't do it already) you should set up the code to handle the user input correctly.

If you need an easy way to detect what the return value of the msgbox is (which also proves what we've been saying about the values returned from different button sets/buttons pressed) you can have a look at what's produced in the Immediate window using:
Code:
Debug.Print MsgBox ("Click Me", YourButtonSetToTest)
No matter how you close the messagebox (short of killing the application's process) it will tell you what the return value is.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top