Dynamic disable / enable of Windows close button

M

Martureo Bob

Is there a technique to ***dynamically*** disable (grey out) and later
re-enable the Windows close ("X") button?

Here's why I ask...

My form can enter a critical processing phase where the user has gone into
"Add" mode (that's something within my application). The form's fields are
bound to the query, and some of the form's fields are defined in the table
as "required". If the user clicks the "X" before all the required fields
were entered, an error occurs because Access is then trying to close the
form but one or more of the table's properties are being violated.

BTW, my form has "Save" "Cancel" "Add" "Delete" and "Change" buttons.

I coded an OnUnload event with the hopes of canceling the close, but that
event occurs too late.

Aas a workaround, I added my own close button (control) on the form and
disabled the "X" in the control box property setting. I have an "OnClick"
event for that button that can intercept the situation and reject the user's
request to close the form --- but my users don't like the button --- they
want the "standard" way of closing the form (with the "X").

So I poked around the internet trying to try and find a WIN 32 API method of
greying out the "X" but I came up short.

I had thought of making all the form's fields "unbound" and then I suppose
the problem would go away. But then I would have to mess with the rest of
the code so that all those unbound fields would be moved to the database
when the user finally got around to clicking the form's "Save" button.

I would rather diddle with the "X" --- especially since this same situation
occurs of 4 of my application's forms.

Any clues?

THANKS!!!!

Bob (@Martureo.Org)
 
M

Martureo Bob

This looks exactly like what I'm trying to do. I'll copy and paste the code
and give it a try.

THANKS!

Bob (@Martureo.Org)
 
M

Martureo Bob

The code in the article you referred me to works perfectly! Thanks....

Unfortunately, it does not work in the environment that I use.

My forms are modal popups (all running maximized) and controlled by my own
"swithcboard"...

The "X" close button that is disabled is one for the Access Application
(which always remains hidden) and not for the maximized modal popup form
that is currently on the screen.

I need to have the form that's on the screen execute the "disable" at one
point in its processing, and execute the "enable" at a subsequence point in
its processing.

In the article, I see this line of code (in two places):

hWnd = Application.hWndAccessApp

How do I properly modify this line so that it's pointing to the hWnd of my
modal popup form

Thanks in advance!

Bob (@Martureo.Org)
 

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