locking form controls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashwinidubey
    New Member
    • Nov 2011
    • 5

    #1

    locking form controls

    i want to add to a button to the form to lock/unlock the controls, so that nobody accidentally changes the data. In one form i had the controls to be locked in a subform so i just locked it through the change property, but in the main there are several controls and changing the property of every control is not possible, so is there any other way to lock the controls of the form, i tried changing the recordset to snapshot, but i think i can't handle the recordset properly
    so i am left with no result. Please any body help, how can i lock the controls on the form.

    thanks in advance
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can either use a loop to lock all the controls. Or put the main form into a subform and lock that.

    Comment

    • ashwinidubey
      New Member
      • Nov 2011
      • 5

      #3
      how to loop the controls. please tell, as i am novice and dont know much about programming.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You can use the for each construct to loop through all the controls in the Form.Controls collection.

        Comment

        • ashwinidubey
          New Member
          • Nov 2011
          • 5

          #5
          sorry i didnt get what you said...

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            Originally posted by Ashwinidubey
            Ashwinidubey:
            sorry i didnt get what you said...
            You don't say which part was unclear, which rather implies all of it is. This would indicate you have almost no experience in Access VBA. Something you should mention if you don't want all replies to go over your head.

            What Rabbit is referring to is a basic For Each loop construct in your code something like :
            Code:
            Dim ctl As Control
            
            For Each ctl In Me.Controls
                ctl.Locked = True
            Next ctl
            This won't work directly as some controls won't have a .Locked property, but it illustrates the concept. Also you didn't indicate in your question how you might determine the controls you're interested in so I couldn't include that in any example code obviously (I would hope).

            Comment

            Working...