set Form Close button via code

D

dymondjack

Hi again and TIA

Does anyone know how to toggle a forms control box via code? I have a 'high
security' form and the user needs to unlock the record before changing any
values. I would like to be able disable the control box while the record is
unlocked (or at least the close button, I'm not all that much concerned with
min/max), and enabled when the record is saved and returned to its normal not
dirty state.

I thought that Me.ControlBox = False would work, but I get an error saying
that I cannot assign a value to this property.

Online searches seem to return only information on setting the Access window
close button, rather than specific forms.

Any ideas?

Thanks

--
Jack Leach
www.tristatemachine.com

- "A designer knows he has reached perfection not when there is nothing left
to add, but when there is nothing left to take away." - Antoine De Saint
Exupery
 
D

Douglas J. Steele

The Help file states "You can set this property only in form Design view."

You'd have to open the form in Design view, set the property, then open it
in Normal view. Note that that will prompt the user "Do you want to save the
changes" when they close the form, unless you close the form using

DoCmd.Close acForm, Me.Name, acSaveNo

(and you won't be able to do that if they simply click on the Close button
at the upper right-hand corner of the form.)
 
D

dymondjack

Thanks... sorry about the post, apparently I should have done more homework
before asking.
--
Jack Leach
www.tristatemachine.com

- "A designer knows he has reached perfection not when there is nothing left
to add, but when there is nothing left to take away." - Antoine De Saint
Exupery
 
D

Dale Fye

In cases like this, I generally create a variable (AllowClose) that is public
to the form. In the Forms Open event, I set that value to False.

Then, in the Forms Unload event, I check to see whether AllowClose is false,
something like:

Private Sub Form_Unload(Cancel as integer)

if me.AllowClose = False then
msgbox "Use the Close button to close this form!"
Cancel = true
endif
End Sub

Then, I add a command button (cmd_Close) to the form, with Click code
similar to :

Private Sub cmd_Close_Click

AllowClose = True
Docmd.close acform, me.name

end sub

This will disable the forms. Realistically, you don't have to change the
forms Close button or control box property, because the Unload event will
intercept that action, and prevent the form from closing if the user didn't
hit the "Close" command button.
--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
D

dymondjack

Dale,

Great idea... thanks!

I hadn't thought of validating a close throught the form's unload event.
I've already got variables set up that records the form state (depending if
its a high security (records need unlocking to edit), normal security, clean
and dirty & numerous save validations for each type). This is an easy fix,
being that I've already got the flags in place to handle the header button
formats.

Thanks again

--
Jack Leach
www.tristatemachine.com

- "A designer knows he has reached perfection not when there is nothing left
to add, but when there is nothing left to take away." - Antoine De Saint
Exupery
 

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