Allowing Edits

G

Guest

Hello Everyone!

I have a form that I would like to do the following:

1. Have all new records open to add information

2. Have all previous records Non Editable (all fields are locked)

3. I need to make the previous records editable if the managers need to
edit. I was hoping to set up a command button that would make all the records
editable and once the manager closes the form, the previous records go back
to being uneditable.

I am a novice so please simplify answers and thank you in advance for any
help!!
 
G

Guest

The first two are easy. Allowing the manager special permissions is more
troublesome.

Put this in the Current event of your form to Lock controls for existing
records and unlock them for new records.

Dim ctls As Controls
Dim ctl As Control

Set ctls = Me.Controls
For Each ctl In ctls
If Nz(Switch(ctl.ControlType = acComboBox, True, ctl.ControlType =
acTextBox, _
True, ctl.ControlType = acListBox, True, ctl.ControlType =
acCheckBox, _
True), False) Then
ctl.Locked = Not Me.NewRecord
End If
Next
Set ctl = Nothing
Set ctls = Nothing

The above code will handle combo boxes, text boxes, list boxes, and check
boxes. If there are any other types of controls you want to lock, you will
need to add them to the Switch function.

Allowing the manager to edit existing records is not hard, but also not
secure. Unless you have Access security implemented, it is not hard to get
around any password or home grown security.
The easiest, of course would be to put code behind the command button that
would get the manager to enter a password. If the password has been entered.
then unlock the controls for the manager. The code would be the same as
above except the line ctl.Locked = Not Me.NewRecord would just be ctl.Locked
= False
 
D

Debra Farnham

Hi Doug

You can very easily have the form open to a brand new record and not display
existing records by setting the Data Entry property on the form to Yes.

By adding a password protected button (for what's it worth as it is
difficult to prevent hacking), you can set the Data Entry property on the
form back to its default Yes for the managers and on the close event of the
form, reset the Data Entry property to Yes.

I am assuming you wanted the users (excluding managers) to have the ability
to add new records and just not be able to edit existing ones.

HTH

Debra
 
G

Guest

Hi Klatuu,

I plugged in the code and this part of it is in red.

If Nz(Switch(ctl.ControlType = acComboBox, True, ctl.ControlType =
acTextBox, _
True, ctl.ControlType = acListBox, True, ctl.ControlType =
acCheckBox, _
True), False) Then

It ask me to debug when I go to a new record.
 
B

Beatrix J B

How about on load property put a code for me.allowedits = false and put a
password protected button with a me.allowedits=true ... And an after update
code to me allow edits=false?
 
G

Guest

Hi Beatrix J B!!

I tried it without the paasword button but just a plain button that gives
the allow edits command. Worked like a charm and was very simple to do!!!!!

Thank you so much for your help!!!!!!
 
G

Guest

Beatrix J B said:
How about on load property put a code for me.allowedits = false and put a
password protected button with a me.allowedits=true ... And an after update
code to me allow edits=false?
 

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