Full Version: Selective lock/unlock
UtterAccess Forums > Microsoft® Access > Access Forms
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?
Set the Allow Deletes property of the form to No.
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.
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 ...
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 ...
R. Hicks
Why have got this line in your code:
You have not "Set" anything in your code .. only Dim'd a variable ...
grin.gif old habit.
R. Hicks
Not needed .. as it does nothing.
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?
On Current Event of a form.
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.
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 ..
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.
Glad to be of help. thumbup.gif
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.