Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2001
    New York
    Thanked 0 Times in 0 Posts

    Graying Out Fields (Access 97 SR2)

    I currently have a DB where when the the closed checkbox is checked, all the fields in the form a grayed out so no one can make changes to them. My code is as follows, at least part of it:

    Private Sub Closed_AfterUpdate()
    If Me!Closed = -1 Then
    Me!IndexNo.Enabled = False
    Me!DocketNumber.Enabled = False
    Me!CaseName.Enabled = False
    Me!PlaintiffFirstName.Enabled = False
    Me!PlaintiffMI.Enabled = False
    Me!PlaintiffLastName.Enabled = False
    Me!PlaintiffName.Enabled = False

    I have to create the same type of a situation in a DB with over 100 fields, and I don't want to have to type each one can I have it do the same thing with all the fields in the form without typing each separately?


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Graying Out Fields (Access 97 SR2)

    If you want to disable *all* controls on the form that can be disabled, you can use

    Private Sub Closed_AfterUpdate
    Dim ctl As Control
    ' Not all controls can be disabled - prevent errors
    On Error Resume Next
    If Me.Closed = True Then
    ' Loop through all controls
    For Each ctl In Me.Controls
    ctl.Enabled = False
    Next ctl
    Set ctl = Nothing
    End If
    End Sub

    Note that this will also disable any command button on the form. For a method to enable/disable controls selectively, see <post#=231124>post 231124</post#>.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts