Change the [locked] property to more than one field at a time?

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

Guest

Can I change the [locked] property to more than one object at a time. I have
a form with several fields that need to be locked. I wish I could just
highlight them all and do it.

Thanks
 
Click on your first control, then hold the shift key down and click on other
controls. When you then change the locked property it will apply to all the
controls selected.
 
Hi, Paul

It depends upon whether you want to change the property while in Design View
or in Form View. When in Design View, open the Properties dialog window and
select the "Data" tab, then use the left mouse button to select and "draw" a
box from the top left to bottom right corner to enclose the group of objects
you want to change the property for. Once selected the Properties dialog
window, Title Bar will change to "Multiple Selection," and one can change the
combo box for the Locked Property to Yes or No. This change will apply to
all objects currently selected. If the objects are scattered around the
form, then hold the <SHIFT> key down and left click on each object to select
multiple objects.

If in Form View, then one could do this programmatically, say with a click
of a button to toggle the form from edit mode to view only mode. In the
form's module, try:

Private Sub ViewEditBtn_Click()

On Error GoTo ErrHandler

Static fToggle As Boolean

If (fToggle) Then
Call setEditOrViewMode(Me, "Edit")
Else
Call setEditOrViewMode(Me, "View")
End If

fToggle = Not (fToggle)

Exit Sub

ErrHandler:

MsgBox "Error in ViewEditBtn_Click( ) in " & vbCrLf & _
Me.Name & " form." & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

In a standard module, try:

Public Sub setEditOrViewMode(frm As Form, sMode As String)

On Error GoTo ErrHandler

Dim idx As Long

'---------------------------------------------------------
' Determine whether in "Edit/Add" mode.
'---------------------------------------------------------

If (sMode = "Edit") Then
frm.AllowAdditions = True
frm.AllowDeletions = True
frm.AllowEdits = True

For idx = 0 To (frm.Controls.Count - 1)
If (frm.Controls.Item(idx).ControlType = acTextBox) Then
frm.Controls.Item(idx).Locked = False
End If
Next idx

'---------------------------------------------------------
' Determine whether in "View" mode.
'---------------------------------------------------------

ElseIf (sMode = "View") Then

frm.AllowAdditions = False
frm.AllowDeletions = False
frm.AllowEdits = False

For idx = 0 To (frm.Controls.Count - 1)
If (frm.Controls.Item(idx).ControlType = acTextBox) Then
frm.Controls.Item(idx).Locked = True
End If
Next idx
End If

Exit Sub

ErrHandler:

MsgBox "Error in setEditOrViewMode( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub

Of course, this will lock/unlock all text boxes, not just certain ones, so
change the example as needed.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.


paulpenta said:
Can I change the [locked] property to more than one object at a time. I have
a form with several fields that need to be locked. I wish I could just
highlight them all and do it.

Thanks
 
Back
Top