Removing ALL Control Boxes

D

DubboPete

heya all,

On a roll here with questions... I know it's pretty simple to
disable the control box, min/max buttons and close button, but the
question is...

Can the same be done for the program? I am trying to get users to
close down via command buttons on a form, and not via the main
Microsoft Access Close button in the top right hand corner...

Just a thought

DubboPete
ps, got a beer now.... refer to my earlier posting for reference :)
 
D

Douglas J. Steele

Well, you can use the code in http://www.mvps.org/access/api/api0019.htm at
"The Access Web" to actually remove the Access window itself, but note that
that can lead to issues.

A simpler approach is simply to ensure you have a form that's always open
(even if it's not visible), and to put code in that form's Unload event to
prevent the application from closing. In a nutshell, you need some way of
knowing that they're trying to close the application properly, such as a
global variable that's set to True when they click on the appropriate Close
button. You'd then use:

Private Sub Form_Unload(Cancel As Integer)

If booOkayToClose <> True Then
Cancel = True
End If

End Sub
 
C

Cheese_whiz

Hi DubboPete,

I came up with this:


Option Compare Database
Option Explicit
_____________________________
Function CloseControlBoxes()

Dim i As Integer
Dim doc As Document
Dim db As Database

Set db = CurrentDb

DoCmd.SetWarnings False
For i = 1 To db.Containers("forms").Documents.Count - 1

Set doc = db.Containers("forms").Documents.Item(i)

DoCmd.OpenForm doc.Name, acDesign

If Forms(doc.Name).ControlBox = True Then
Forms(doc.Name).ControlBox = False
Debug.Print doc.Name & ": controlbox property set to false"
End If

DoCmd.Close acForm, doc.Name

Next i

DoCmd.SetWarnings True


End Function
_____________________________________

I tested it, and it seems to work fine. If you want to confirm each change,
then comment out the Docmd.SetWarnings lines.

Add this code to a new module, then in the immediate window type:

?CloseControlBoxes()

and then hit the enter key.

Hope that helps.
CW
 

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