• For each next loop (97)

    Author
    Topic
    #366130

    For each next loop
    I typed the following but get the error that

    Viewing 1 reply thread
    Author
    Replies
    • #566885

      Hi,
      Not all controls have the same properties – for example, labels do not have Locked or Enabled properties. Therefore, if you have any labels on your forms you will get errors with that code. You may want to use ctl.ControlType to ensure that your code only runs on the relevant controls.
      Hope that helps.

      • #566914

        or put in some error trapping that moves to the next control

        • #566978

          …or put a value in the Tag property of controls you wish to manipulate in this fashion, and test for the presence of that value inside the loop.

    • #567047

      You also need to change your code to this:

      For Each ctl in [Forms]![frmDataEntry].Controls

      And then you can use something like this:

      Select ctl.ControlType
      Case acTextBox, acComboBox, acToggleButton, acListBox
      ctl.Locked = True

      End Select

      • #567436

        Thanks, but I got to it using this way:

        ‘lock record if submitted…
        If IsNull(Me.DateSentToAccounting) = False Or IsNull(Me.DateSentToJon) = False Then
        For Each ctl In Me.Controls
        If ctl.ControlType acTabCtl Then
        If ctl.ControlType acPage Then
        If ctl.ControlType acLabel Then
        If ctl.ControlType acCommandButton Then
        ctl.Locked = True
        ctl.Enabled = False
        End If
        End If
        End If
        End If
        Next ctl
        End If

        The above will lock the controls on the form nicely (basically all of them) but when I try to unlock I

        • #567444

          It looks like Shane probably had the right idea in using theTag Property to let you check for info abut the control, then decide if to leave locked or unlocked!

          Peter

        • #567451

          Hi,
          I’d suggest you use the select case method that Charlotte suggested as it will be quicker than multiple If statements. Something like:
          For Each ctl in [Forms]![frmDataEntry].Controls
          with ctl
          Select Case .ControlType
          Case acTextBox, acComboBox, acToggleButton, acListBox
          .Locked = True
          .enabled = false
          .tag = “LockedByMe”
          case else
          end select
          end with
          next ctl

          then to unlock them you can use:

          for each ctl in me.controls
          with ctl
          if .tag = “LockedByMe” then
          .locked = false
          .enabled = true
          .tag = “”
          end if
          end with
          next ctl

          Hope that helps.

    Viewing 1 reply thread
    Reply To: For each next loop (97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: