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

closebutton property doesn't work when window is maximized 1

Status
Not open for further replies.
May 30, 2001
17
0
0
US
Running Access 97 on NT4 SP6.

I do not want users hitting the "X" to close a form, but when I try to disable it using the closebutton property or by setting the close button to "no" in the form properties with the window maximized, that little "X" is hanging around. If the window is not maximized, the close button is not available.

I have special validation code that checks fields on the form prior to closing the form. No matter what I do, if the user clicks the "X" Access will generate the message:


Microsoft Access
You can't save this record at this time. Microsoft Access may have encountered an error while trying to save a record. If you close this object now, the data changes may be lost.

Do you want to close the Database object anyway?

This error is generated after the Form_BeforeUpdate event which I attempt to cancel but still recieve the Access error message about saving a record (Didn't I cancel the record save already?).

This app is distributed to hundreds of computers with different screen resolutions so the window must be maximized, but I do not want them seeing the message as these people are 100% computer illiterate and will call me as soon as they see that message. The other problem is that this message has no error number for me to trap but still appears even with "SetWarnings = No".

Any assistance is supremely appreciated.
 
This should work whether you have the Close button enabled or not.

In the Declarations section of your Form:

Dim booCanClose As Boolean

In the On Load or On Open event:

booCanClose = False

In the On Click event of your Close button:

booCanClose = True
DoCmd.Close acForm, Me.Name

In the Form's UnLoad event:

If booCanClose = False Then
MsgBox "Improper logout method:"
Cancel = True
Else
MsgBox "Proper logout method:"
Cancel = False
End If

Obviously, edit the above to suit your own needs and remember this is an example, not a solution, you will have to put your own code in to make it work exactly as you want.

But basically, the user can't close the form until you decide booCanClose = True.

Bill
 
Appreciate the code snippets Billpower.

The real problem isn't forcing the user to stay on the form, it's getting rid of that message that only appears when the "X" close button is clicked. I can't even trap the error in the Form_Error event and yet it doesn't appear to be a warning since it continues to appear with the SetWarnings=No. The error occurs prior to the Form_Unload event so I can't even cancel that to avoid the issue.

Is there possibly a way to size the form without using "Maximize" that would apply to all screen sizes (800X600, 1024X768, etc)? My real fear is the number of phone calls this single error message will generate. I currently trap for every error and reword them into simple english to avoid confusing my users.

A definite catch 22 eh?
 
Hi phishman00,

They're not code snippets, that was clean new code that I wrote for someone over the weekend who actually didn't have the manners to let me know how they got on.

I honestly find this problem you're experiencing quite intriguing, so am willing to look at your DB if you want.

My email is billpower@cwcom.net

Remove any sensitive records first and please zip up the DB.

Will post any recommendations here ASAP (If any)

Bill
 
Billpower,

I ended up suppressing all error messages on the form and implementing sections of your code.

I have one last bug that I can't figure out how to get around. Maybe you can help.

My validation code for the data resides in the Form_BeforeUpdate event. This event will trigger if the user entered any data regardless of any code I put in the Form_Unload event.

Is there any way of checking if a form is in the process of being closed? I ask because I want to skip data validation altogether if the user clicked on the close button. I can keep them on the form, but I can't stop that BeforeUpdate from occuring. I would like to add code in the BeforeUpdate event to see if the form is trying to be closed and exit the sub if possible.

Ideas?

Thanks again.
 
Hi phishman00,

I've had a good look in to this, this morning. I can't see any way to control the BeforeUpdate event. As soon as say a Button is clicked, before any variable or code in that Button can be read, the BeforeUpdate event is fired. So I have to say I'm beaten on this one.

I am still willing to take a look at your DB, you shouldn't need to be suppressing error messages. Up to you.

Bill
 
Thanks for the offer. Although I can't find documentation for that error, I trapped for err.number = 0 specifically and it seems to take care of the problem. I have also changed the error messages to handle both situations of data validation and closing the form.

Thanks for the help. Always greatly appreciated. Now if I can just figure out how to get SBC to stop disconnecting my internet service every other day, I'll be in great shape.

Take care.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top