Full Version: Selective lock/unlock
UtterAccess Forums > Microsoft® Access > Access Forms
the_b_man
I'm trying to create a form where the user can create new records, and edit select fields of existing records, and not delete.
tried locking fields, but that stops the user from typing in them when they go to create a new record.
Otried saying "Edit" "no" in the form properties, and unlocking the fields, which allows them to add, but now they can't edit any existing fields.
Does anyone know of a solution?
fkegley
Set the Allow Deletes property of the form to No.
the_b_man
Thanks for the response.. but, I guess I didn't explain what I meant properly. (I've been up way too long working on this)
want the user to be able to edit SOME fields, but not all of them. But when they make a new entry, to be able to type in ALL fields.
Locking individual fields stops them from typing in those boxes when they make a new record. Disallowing edits obviously stops them from editing any boxes, except when making a new record.
Hope I explained it better this time.
JayNoelOlimpo
Hi;
Try this one ...
Add in each control in which you want to lock Other tab of a control | Tag = "Locked"
On Current event of a form ...
CODE
Text2.SetFocus
Dim ctrl As Control
For Each ctrl In Me.Controls
    If ctrl.Tag = "Lockme" And Not Me.NewRecord Then
        'ctrl.Locked = True
        ctrl.Enabled = False
    ElseIf ctrl.Tag = "Lockme" And Me.NewRecord Then
        ctrl.Locked = False
        ctrl.Enabled = True
    End If
Next ctrl
Set ctrl = Nothing

You also have to set focus on the control that will not be disabled/enabled ...
HTW.
R. Hicks
Why have got this line in your code:
You have not "Set" anything in your code .. only Dim'd a variable ...
DH
JayNoelOlimpo
grin.gif old habit.
R. Hicks
Not needed .. as it does nothing.
DH
the_b_man
Wow thanks for coding that for me! That's a clever approach. Sorry again though, but I didn't catch what event the code should go under?
JayNoelOlimpo
On Current Event of a form.
GOOD LUCK!
the_b_man
I went to the VBA editor, and chose "Form" from the first dropdown, then looked in the 2nd one... I see "Load" and tonnes of other stuff (ie. selecting this makes me a Form_Load)
hich one should I pick from the list? I'm not sure what you mean by, on current event.
JayNoelOlimpo
Open the form in design mode.
oto View | Properties ...
Event Tab | On Current | [Event Procedure] | then click on the [...]
Which will then load the VBA editor ..
the_b_man
Brilliant THANK YOU. I'm rediculously stressed out over this project right now and you (and everyone else who's put up with me tonight) have helped me a great deal.
JayNoelOlimpo
Glad to be of help. thumbup.gif
GOOD LUCK!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.