Unlock TextBox (1 Viewer)

kmrkmj

New member
Local time
Today, 05:12
Joined
Nov 2, 2006
Messages
5
Hello,

I'm using this bit of code to lock my controls on a form

Code:
Private Sub Lock_Controls()

'Locks the controls to prevent editing

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

    txt_SearchBox.Enabled = True

End Sub

I have a "Edit" button that will run the opposite code to unlock the controls which works fine. My problem is that I want txt_SearchBox in the header to remain enabled to search the continuous form but it remains locked until I hit the "Edit" button. Any ideas?
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:12
Joined
Sep 21, 2011
Messages
14,287
Me.txt_Searchbox.Enabled = True ?

Or when you process the textbox controls, check it's name and skip if the search box?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:12
Joined
Oct 29, 2018
Messages
21,471
Hi. Another approach is to use the control's Tag property, You simply tag the ones you want locked and leave the other ones alone (empty).
 

kmrkmj

New member
Local time
Today, 05:12
Joined
Nov 2, 2006
Messages
5
Me.txt_Searchbox.Enabled = True ?

Or when you process the textbox controls, check it's name and skip if the search box?


Yep your question mark made it click for me. I was using enabled instead of lock. Thanks!
 

Users who are viewing this thread

Top Bottom