• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 632
  • Last Modified:

How lock all fields on a form EXCEPT one field if certain criteria exists

I need to be able to lock all fields on a form if certain criteria exists.

Something like this in the onopen event of the form: (which of course isn't even close)

If me.cboStatus = 1 then
Me.locked except me.cboStatus
endif
0
SteveL13
Asked:
SteveL13
  • 2
1 Solution
 
Jeffrey CoachmanCommented:
Then you will have to note all the types of control you will be locking.
textboxex, comboboxes, ...etc...

Not all controls can be locked, ...so you cant just loop all of them

In any event...
Code would be roughly something like this:

Dim ctl As Control

If Me.cboStatus = 1 Then
    For Each ctl In Me
        If (ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox) Then
            If ctl.Name <> "cboStatus" Then
                'MsgBox ctl.Name
                ctl.Locked = True
            End If
        End If
    Next ctl
Else
    For Each ctl In Me
        If (ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox) Then
            If ctl.Name <> "cboStatus" Then
                'MsgBox ctl.Name
                ctl.Locked = False
            End If
        End If
    Next ctl

End If



JeffCoachman
0
 
Jeffrey CoachmanCommented:
The code above would go on the current event...
0
 
EirmanCommented:
Not exactly what you requested but worth considering ....
if you want manual control of field locking have a look my solution here
http://www.experts-exchange.com/Database/MS_Access/Q_28374881.html
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now