Problems with users closing forms.

G

Guest

Like many before me I need my users to close most of my forms by clicking on
a Close button on these forms. I have seen how to prevent the Access
application window from closing by using the OkToClose trick in the Unload
event of a hdden form. But what I have not been able to find is a way to
prevent my user from closing any form by simply right-clicking on the form
name in the task bar and then selecting Close. I understand that the
OkToClose option would also work here, but this is simply not practical,
since it also prevents the form from switching to design view during
development. I can't figure out why, if the forms 'X' is disabled, it is
still enabled in the task bar. Is there any way to programmatically disable
these options in the task bar?
Thank You!
Paul
 
R

Rick Brandt

Paul said:
Like many before me I need my users to close most of my forms by
clicking on a Close button on these forms. I have seen how to prevent
the Access application window from closing by using the OkToClose
trick in the Unload event of a hdden form. But what I have not been
able to find is a way to prevent my user from closing any form by
simply right-clicking on the form name in the task bar and then
selecting Close. I understand that the OkToClose option would also
work here, but this is simply not practical, since it also prevents
the form from switching to design view during development. I can't
figure out why, if the forms 'X' is disabled, it is still enabled in
the task bar. Is there any way to programmatically disable these
options in the task bar?
Thank You!
Paul

First, let's examine the original premise. Why do you need them to use your
close button instead of closing by the normal means? Most likely this is
only a perceived requirement rather than an actual one.

If it is because you are running code in your custom close button prior to
closing the form you should be able to move that code to the Close event of
the form. The Close event can even be cancelled should your code determine
that the user did something (or didn't do something) that needs to be
remedied before allowing them to close the form.
 
G

Guest

Thank you Rick, a change of perspective on this problem is exactly what I
needed!

I went ahead and implemented your suggestion and here is my problem now.
My Close button was performing a Refesh to commit the last record entered.
In doing so, this action would fire off the Form Error event if any issues
were detected. I figured all I had to do was move the Refresh to the Unload
event and cancel if there are any issues. It seemed perfect, until I
discovered that the Refresh in the Unload doesn't seem to be doing anything,
it is not firing the Error Event. It would appear that any controls with data
in them are flushed before the Unload occurs and the data for the last record
entered are lost. Any ideas or suggestions would be appreciated.
Thank You!
Paul
 
G

Guest

Update!

After further investigation, I stand corrected, the Error Event does trigger
if there is a problem with the current record when Alt-F4 is applied.

The only problem (not a big one) now, is that I don't know how to replace
the error message generated by Access saying "You can't save this record at
this time... Do you want to close the database object anyway?" and get the
same functionality. In other words, I can generate my own message and if the
user doesn't want to exit I can set a flag to cancel the Unload Event, but
existing data in the rew record that was just being created is deleted from
the form. Needless to say, pretty annoying since the data needs to be
reentered. If I let the Access error message through, and the user selects
No, the data for the record being created is not wiped out from the form???

Thanks again!
Paul
 

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