Uneditable form

N

Neil Greenough

I have a frmContacts that contains info for volunteers for my organisation.
I want to secure this form so that the info on it cannot be edited and only
viewed. Nonetheless, I also want to add a button on the form says 'edit' and
when clicked, unsecures the form allowing it to be edited. Having said that,
I want three fields within the form to remain locked so that they can't be
edited, but the rest of the info can. Those fields are called 'Area'
'Neighbourhood' and 'Station.'

Anybody give me a step-by-step guide please?
 
V

Van T. Dinh

* Set the Form's RecordSource to Dynaset and AllowEdits to True / Yes.
(Note: the RecordSource must be editable).

* Set Enabled Property to False and Locked Property to True for each
editable Control on your Form except the "Edit" CommandButton (Enabled =
True).

* In the Click Event of "Edit" set Enabled to True and Locked to False for
each Control except the 3 Controls you want to remained locked and the
"Edit" CommandButton.

HTH
Van T. Dinh
MVP (Access)
 
D

Dirk Goldgar

Van T. Dinh said:
* Set the Form's RecordSource to Dynaset and AllowEdits to True / Yes.
(Note: the RecordSource must be editable).

* Set Enabled Property to False and Locked Property to True for each
editable Control on your Form except the "Edit" CommandButton
(Enabled = True).

* In the Click Event of "Edit" set Enabled to True and Locked to
False for each Control except the 3 Controls you want to remained
locked and the "Edit" CommandButton.

Hi, Van. It seems to me that Neil need not change any of the Enabled or
Locked properties from their design-time settings. Wouldn't it be
enough to have those three controls as locked, and leave all the other
controls as unlocked? Then just changing the form's AllowEdits property
from False to True would be enough to allow all other controls to be
edited, but those three would remain locked. Have I overlooked
something?

Neil probably wants to have AllowDeletions and AllowAdditions set to
False, too.
 
V

Van T. Dinh

Dirk

That should be enough.

It is my habit (at the moment) that I don't set AllowAdditions to False. In
the current database, the client doesn't want to delete any Record and
simply mark old Records as inactive. Normally, they only want to see active
Records but they want the option to see inactive Records as well. We have
an unbound OptionGroup on the Form header so that the user can select active
/ inactive (default to active on opening). This unbound OptionGroup won't
work if the Form's AllowEdits is set to False and hence I don't this to
False on any Form at the moment.

Thanks & cheers
Van T. Dinh
MVP (Access)
 
D

Dirk Goldgar

Van T. Dinh said:
Dirk

That should be enough.

It is my habit (at the moment) that I don't set AllowAdditions to
False. In the current database, the client doesn't want to delete
any Record and simply mark old Records as inactive. Normally, they
only want to see active Records but they want the option to see
inactive Records as well. We have an unbound OptionGroup on the Form
header so that the user can select active / inactive (default to
active on opening). This unbound OptionGroup won't work if the
Form's AllowEdits is set to False and hence I don't this to False on
any Form at the moment.

Good point. I've run into that problem before, and had to solve it by
locking and unlocking the controls instead, as you have done.
 
N

Neil Greenough

I am up to the final part, adding the 'on click' event procedure.

Could you let me know what to type? So, say the ones I DON'T want to allow
to be edited are "Name" "Address" and "telephone."

How do I type this in as VBA

(* In the Click Event of "Edit" set Enabled to True and Locked to False for
each Control except the 3 Controls you want to remained locked and the
"Edit" CommandButton.)
 
N

Neil Greenough

If I follow this method, what code should I put behind the button to make it
allow the fields to be editable?
 
N

Neil Greenough

If I follow Dirk's method, what code should I put behind the button to
release the fields so they can be editted? Could you give me an example of
the code?
 
D

Dirk Goldgar

Neil Greenough said:
If I follow Dirk's method, what code should I put behind the button to
release the fields so they can be editted? Could you give me an
example of the code?

The idea here is that you design the form with everything normal, except
that for those three fields you set the Locked property to Yes, and you
set the form's AllowEdits property to No. If you don't want the user to
be able to delete or add records, also set the form's AllowDeletions and
AllowAdditions properties to No. All of this is done at design time,
not at run time.

Then, in your "unlock" button's Click event procedure, you have just
this one line of code (besides the "Sub" and "End Sub" lines:

Me.AllowEdits = True

That's it. Would you want to lock the form again, afterward? If so,
you might want to put this line in the form's Current event:\

Me.AllowEdits = False

That way, each time you go to another record, the form is locked until
you click the button to unlock it.
 

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