Lock All Fields Except One

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form which I wanted to lock all the fields unless the Edit button is
clicked, except for one combo field. If I use the AllowEdits = False, the
combo box would be locked as well. Someone in this forum suggested using the
Tag property but I found that I have to always remember to tag any new fields
which I'm still adding in.

Anyone with some other way of doing this: locking all fields, except for one
field? Thanks.
ck
 
I have a form which I wanted to lock all the fields unless the Edit button is
clicked, except for one combo field. If I use the AllowEdits = False, the
combo box would be locked as well. Someone in this forum suggested using the
Tag property but I found that I have to always remember to tag any new fields
which I'm still adding in.

Anyone with some other way of doing this: locking all fields, except for one
field? Thanks.
ck

Here is one way.
In the form's load event:

Dim c as control
On error resume next
For each c in Me.Controls
If c.Name = "ComboName" Then
Else
c.locked = true
End If
Next

Code the Edit button click event:

Dim c as control
On error resume next
For each c in Me.Controls
c.locked = False
Next
 
Is there a way to do this same thing based on the value in a combo box? Such
as when a tech support call is closed, the records can no longer be modifed?
I would still need to view all subforms and reports that were available when
the form was not locked.

Julie Murphy
 
In the form's on current event:

Dim c as control
On error resume next

if me.ComboName="ValueToLock" then
For each c in Me.Controls
If c.Name = "ComboName" Then
Else
c.locked = true
End If
Next
else
For each c in Me.Controls
If c.Name = "ComboName" Then
Else
c.locked = false
End If
Next
end if

Your subforms will continue to be available
 
This almost works for me except that I don't have the combo box that needs to
be left unlocked so I changed the code a little. I used the following code
for the Forms AfterUpdate Event:

Private Sub Form_AfterUpdate()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = True
Next
End Sub

and the following for the Edit Button Click Event:

Private Sub Edit_Record_Click()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = False
Next
End Sub

The problem I'm having is that when I first open the form and add a new
record, then click the add new record button I can't just start typing I
first have to click on the edit button and then start typing into the fileds.
Is there a way to fix that?

Thank you.
 
You can create an add new button to the form which adds a new record.
On the ON CLICK event write the following code:

Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = False
Next
GoTo.Record , , acNew
 
Back
Top