Lock and Unlock a Form

A

ATSBC03

I have read many of the other posts in regards to locking and unlocking forms
but i am still unable to get it to do what i want. Let me explain my setup.

I am working on form to help capture incidents that we have. Each form can
have up to 4 subforms. 1 subform is embedded on the main form and the others
are on tabs and can be opened using an option group. I have one main number
as a key to group all the forms together in a 1-1 relationship.

On the main form I have added a combo box with "open" and "close" to help
prevent accidental erasing of already entered records. The form does not have
an update or close button. New records are added using the record selectors
and close buttons already there.

I set my open/close combo box to open. It can be changed to close which
calls on the following code in the after update event of the combo box and
the form current event :

If cboOpenClosed = "Closed" Then
Me.AllowEdits = False
Me.FallRisKParametersSub.Locked = True
Me.subFormLab.Locked = True
Me.subHospitalTransfer.Locked = True
Me.subRiskManagement.Locked = True
Me.MgrFollowUpSub.Locked = True
Me.Form.AllowEdits = False
ElseIf cboOpenClosed = "Open" Then
Me.AllowEdits = True
Me.FallRisKParametersSub.Locked = False
Me.subFormLab.Locked = False
Me.subHospitalTransfer.Locked = False
Me.subRiskManagement.Locked = False
Me.MgrFollowUpSub.Locked = False
Me.Form.AllowEdits = True
End If

This code successfully locks or keeps unlocked my forms.

The problem:

If i find out that i need to add something to a record that is already
closed i cannot select open on the combo box. Is there a way for me to have
that unlocked with all other controls locked? I have to many controls and
really do not want to have to code each control to locked. Any help would be
appreciated. I have been working on this for weeks now and have not made it
anywhere. If you need more information let me know.
 
N

n00b

Yes the problem is you are not allowing edits on the form with the
combo box. This is a problem because as you have found out, you
essentially prevent everything on the form from being changed.

So, you always have to allow edits on the main form.

You will have to lock/unlock each control on the main form explicitly
(except the combobox that opens/closes)
 
A

Allen Browne

That's the point of the code in this link:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Yes the problem is you are not allowing edits on the form with the
combo box. This is a problem because as you have found out, you
essentially prevent everything on the form from being changed.

So, you always have to allow edits on the main form.

You will have to lock/unlock each control on the main form explicitly
(except the combobox that opens/closes)
 
?

.

dans l'article (e-mail address removed), ATSBC03 à
(e-mail address removed) a écrit le 23/01/08 21:33 :
 
A

ATSBC03

I appreciate your help and suggestion. I hadn't tried it that way. I worked
out your code so that now I can unlock and lock a form. I am having a couple
of other problems.

I have added some disabled controls to the exception list, however, i am
having trouble referencing disabled controls on a subform.

I am also having trouble with new records. If I want a new record added it
is locked and i must unlock it before i can enter data. However, I cannot do
that because it is telling me that one of my values cannot be null.

Also, instead of a button i am using a combo box and have. My combo box is
not unbound and is included in the exception list. I want to track then
open/closed so that i can run reports on just those that are open,etc.

Thanks for all your help.
 
A

ATSBC03

Disregard my questions below. I figured out how to reference the controls on
subform or at least work around it so I don't have to exclude them.

I also figured out that instead of adding the line

=LockBoundControls([Form],True) to the OnLoad Event that I could use the
same type of idea that is in the On Click event of my combo box to my Form
current event to get it to look at my combo box with each new record and lock
and unlock based o n whether it is closed or not.

Thanks for everyones help. I just needed the push in the right direction.
 

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