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

Why won't CLoseButton property work?

Status
Not open for further replies.

srast

MIS
Nov 11, 2002
42
US
Hi all.
I have a form with a subform. The OnExit event for the subform control tests for valid input from the user. If it's not valid, I want to disable the navigation and Close buttons (the X), with a Msg box instructing the user how to correct his error. I hid the navigation buttons by setting the property Me.NavigationButtons = False. This works fine, and once the user corrects the error, I reset it to true.
I tried to do the same with the CloseButton property:
Me.CloseButton = False. However, I got an error message saying "Run time error '2448'. You can't assign a value to this object"
Why do I get this error? Any assistance would be greatly appreciated.
Thanks
Steve
 
I believe you are working too hard. Do your subform data validation in the subform control form Before Update code because it presents a Cancel parameter. If you set cancel to true then focus will be returned to the subform regardless of what key the user pressed or where they clicked with the mouse.

Good LucK!
 
SBendBuckeye:
Thanks for your reply. I tried your code, but the subform doesn't respond to the BeforeUpdate event. I beleive that when a form is standalone, then it will respond to those events. However, when it is a subform, only the subform CONTROL responds to events. It only has two events, OnExit and OnEnter. The OnExit event is the one I am using, but I am having the error I mentioned above, that it won't let me set the CloseButton property.
Any other ideas?
Thanks.
Steve
 
To disable closing the form when you don't want it closed, put code in the Unload event that sets Cancel = True unless some condition is met. I do it this way:
Private Sub Form_Unload(cancel As Integer)
'(c)Copyright 2/6/01 Jeremy Wallace
On Error GoTo Error
If Me!cmdClose.Tag = "AllowClose" Then
'continue
Else
MsgBox "Please use the 'Close' button to close this form.", vbOKOnly, "Close Form"
cancel = True
End If
Exit Sub
Error:
ErrorTrap Err.Number, Err.Description, "Form_unLoad", "frmAccount"
End Sub

You'll want to change the error handler.

You'll also want to add code in appropriate places to set the close button's tag to "AllowClose". The ONLY place I do this is when the user clicks the close button, which means that's the only way to close the form. This is an unbound form, so there's code in the Close button to see if the record has been altered and offer to (validate and) save, if so.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Hi Steve!

The close button can't bet set unless the form is in design view. I must agree with SBendBuckeye because I use the form_BeforeUpdate procedure to validate and when I use the form as a subform, my code still runs and event cancel's the event if appropriate. Maybe you have a corruption problem and should try a compact and repair? Possibly your subform needs to be re-created.

hth
Jeff Bridgham
bridgham@purdue.edu
 
jebry:
You are correct. The form does respond to BeforeUpdate event. In the past, I had tried to the use the OnLostFocus and OnGotFocus events, and those did not respond.
Thanks for the info.

JeremyNYC:
Thanks for your code. I used a variation of it, and it works fine.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top