Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2012
    Posts
    3

    Unanswered: How can I lock and unlock edits for all of the text input fields in my forms.

    I have created forms that I use to input device parameters. I have created a button that will lock and unlock the input fields. The issue I have is that I have to enter each field by number into a private sub; some of the form require over 100 entries of lock and then unlock commands. Is there a way to group all of the text fields to unlock them all with one command? I have already numbered them T1 T2 and so on. I can not use the allowedits because it locks my toggle button that I use to unlock the edits.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Here's a solution. The code is to be inserted in the module of the form.
    Code:
    Private m_colTextbox As Collection
    
    Private Sub GatherControls()
    
        Dim ctl As Control
        
        Set m_colTextbox = New Collection
        For Each ctl In Me.Controls
            If ctl.ControlType = acTextBox Then m_colTextbox.Add ctl
        Next ctl
        
    End Sub
    
    Private Sub Command_Lock_Click()
    
        Dim ctl As Control
        
        If m_colTextbox Is Nothing Then GatherControls
        For Each ctl In m_colTextbox
            ctl.Locked = True
        Next ctl
    
    End Sub
    
    Private Sub Command_Unlock_Click()
    
        Dim ctl As Control
        
        If m_colTextbox Is Nothing Then GatherControls
        For Each ctl In m_colTextbox
            ctl.Locked = False
        Next ctl
        
    End Sub
    
    Private Sub Form_Open(Cancel As Integer)
    
        GatherControls
        
    End Sub
    Have a nice day!

  3. #3
    Join Date
    Apr 2012
    Posts
    3

    Locking form text

    Thanks for the reply, but I need somthing a little differant.

    Here is the code I am using that unlock and lock the field the way I need it. The issue I am having is to make it easy to call T1-T10 by combing them in a group somehow and not entering each one like this, some of my forms have over 100 input points that I would have to list one at a time.




    Private Sub Toggle225_GotFocus()
    Me.FormHeader.BackColor = 255
    Me.Detail.BackColor = 255
    Me.Label223.BackColor = 255
    Me.EquipmentName.LOCKED = False
    Me.Function.LOCKED = False
    Me.CALIBRATION_.LOCKED = False
    Me.Position.LOCKED = False
    Me.Last_Update.LOCKED = False
    Me.t1.LOCKED = False
    Me.T2.LOCKED = False
    Me.T3.LOCKED = False
    Me.T4.LOCKED = False
    Me.T5.LOCKED = False
    Me.T6.LOCKED = False
    Me.T7.LOCKED = False
    Me.T8.LOCKED = False
    Me.T9.LOCKED = False
    Me.T10.LOCKED = False

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Quote Originally Posted by Unbound View Post
    The issue I am having is to make it easy to call T1-T10 by combing them in a group somehow and not entering each one like this, some of my forms have over 100 input points that I would have to list one at a time.
    Basically, that's what the code I posted does. If needed, you can use another criteria than the control being a Textbox to add it to the collection e.g.
    Code:
    If ctl.Name Like "T*" Then m_colTextbox.Add ctl
    or
    Code:
    If Left(ctl.Name, 1) = "T" And Val(Mid(ctl.Name, 2)) > 0 Then m_colTextbox.Add ctl
    Moreover, nothing prevents you from manually adding other controls to the collection.
    Have a nice day!

  5. #5
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by Unbound View Post

    ...The issue I am having is to make it easy to call T1-T10 by combing them in a group somehow and not entering each one like this, some of my forms have over 100 input points that I would have to list one at a time.
    The fact that you have over 100 Controls on multiple Forms, and names like T1-T10, or presumably even T1-T100, would seem to indicate that your Database is poorly designed and lacks the Normalization necessary for a well-running app. Most experienced developers will tell you that a Table with more than 25 Fields, or so, is almost assuredly so!

    Perhaps you need to let us know a bit more about exactly what you're trying to do, here, in order for us to help!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    Join Date
    Apr 2012
    Posts
    3

    Locking fields in a form

    The style of the form and the reports as well are laid out to match the manufactures forms to aid in the inputting of new data from the hard copy to the form. I do not do searches, I only print predetermind reports for a hard copy backups. I have attached a screen shot of one of the forms.
    Attached Thumbnails Attached Thumbnails Athena screen.jpg  

Posting Permissions

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