Locking controls in the Detail section of a form

N

Nancy Lytle

Is there any way to lock only the controls in the Detail section of a form.

The page header section has my filtering and navigation, and other standard
buttons. All the data entry is done in the detail section.
I would like to be able to open the form in two ways, one where the users
can edit or add to the form data, another where they can search using the
controls in the form header but they can't edit or add to the data in the
detail section of the form, which also contains a subform.

I have tried the following called in the Current event of the form (I also
tried it in several other events and it didn't do any better):

blnDisable is set in the OnClick event buttons used to open the form (from
another form) for Data Entry or Open for Search only.

Public blnDisable As Boolean ' in declaration section of a module

Public Function fcnCheckDisable()
If blnDisable = True Then
Me.Section(acDetail).Locked = True
Else
Me.Section(acDetail).Locked = False
End If

End Function

Any ideas appreciated,
Thanks,
Nancy Lytle
 
B

Brendan Reynolds

I've used "On Error Resume Next" in the following example to ignore the
error that will be raised if the detail section includes controls, such as
labels and lines, that don't have an Enabled property. There are more
elegant ways to handle this, but I wanted to concentrate on the key issue
here, which is the looping through the controls collection of the detail
section (both the form itself, and each section of the form, have a controls
collection).

It's also important to remember that you can't disable a control while it
has the focus. In this example, the button that fires the code is in the
header section, but if you think that a control in the detail section may
have the focus when the code runs, you will want to set the focus to a
control that is not in the detail section first.

Private Sub Command4_Click()

Dim ctl As Control

On Error Resume Next
For Each ctl In Me.Section("Detail").Controls
ctl.Enabled = Not ctl.Enabled
Next ctl

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 

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