Locking controls on a form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • EJO

    #1

    Locking controls on a form

    TIA!

    I have an A2k mdb which contains a sample record so that my users can
    have an online example of input for a any given field. I don't want
    them to be able to edit the record, but also do not want to prevent
    them from doing a lookup for the live data, so using the allowedits
    property doesn't seem to be an option. Is there a way to lock all the
    controls without listing the over 60 controls individually, then unlock
    the lookup? I tried to use the enumerate controls from the access web
    faq, but haven't been able to modify for this purpose.

  • Grumpy Old Man

    #2
    Re: Locking controls on a form

    "EJO" <5p1der@century tel.net> wrote:
    [color=blue]
    > Is there a way to lock all the
    > controls without listing the over 60 controls individually, then unlock
    > the lookup? I tried to use the enumerate controls from the access web
    > faq, but haven't been able to modify for this purpose.[/color]

    This will lock all text boxes, combo boxes, check boxes and option groups:

    Dim ctl As Control
    For Each ctl In Me.Controls
    If TypeOf ctl Is TextBox Or TypeOf ctl Is CheckBox Or TypeOf ctl Is
    ComboBox Or TypeOf ctl Is OptionGroup Then
    ctl.Locked = True
    End If
    Next

    I'm not sure this is the best solution to your problem, I think you'd need
    to post more info.

    Regards,
    Keith.

    Comment

    • deko

      #3
      Re: Locking controls on a form

      > I have an A2k mdb which contains a sample record so that my users can[color=blue]
      > have an online example of input for a any given field. I don't want
      > them to be able to edit the record, but also do not want to prevent
      > them from doing a lookup for the live data, so using the allowedits
      > property doesn't seem to be an option. Is there a way to lock all the
      > controls without listing the over 60 controls individually, then unlock
      > the lookup? I tried to use the enumerate controls from the access web
      > faq, but haven't been able to modify for this purpose.[/color]

      If you name your controls with a number suffix (the one you want to lock),
      you could put them in a loop. I've done this on occasion.

      Private sub LockControls(bl nLock as boolean)
      Dim ctl as control
      For each ctl in Me.Controls
      If IsNumeric(Right (ctl.name, 2)) Then ctl.Locked = blnLock
      Next
      End sub

      You could do stuff with different number ranges - like enable or disable.
      you might have to check the syntax of my example, but you get the idea...


      Comment

      • EJO

        #4
        Re: Locking controls on a form

        actually, this worked great. thanks for the help!

        Comment

        • Arno R

          #5
          Re: Locking controls on a form

          Maybe just use a 'snapshot' for the forms recordsource and your form will be read-only .
          I don't understand what you mean by 'doing a lookup'.
          --
          Hope this helps
          Arno R


          "EJO" <5p1der@century tel.net> schreef in bericht
          news:1111074394 .837961.253790@ o13g2000cwo.goo glegroups.com.. .[color=blue]
          > TIA!
          >
          > I have an A2k mdb which contains a sample record so that my users can
          > have an online example of input for a any given field. I don't want
          > them to be able to edit the record, but also do not want to prevent
          > them from doing a lookup for the live data, so using the allowedits
          > property doesn't seem to be an option. Is there a way to lock all the
          > controls without listing the over 60 controls individually, then unlock
          > the lookup? I tried to use the enumerate controls from the access web
          > faq, but haven't been able to modify for this purpose.
          >[/color]


          Comment

          Working...