Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lock all textboxes 2

Status
Not open for further replies.

autex

Technical User
Jan 11, 2005
75
US
I have a memo field on a form that I want to always be editable. I want the other fields to be editable only when user presses an edit button. Is there some code that will unlock all textboxes?
 
not clear enough of a question? I know about allowedits, but this won't work because I want one field to be editable all the time. I have a lot of fields so I was looking for an efficient way to do this.
 
You can write a subroutine on your form that will loop through each control and change the settings for enabled and locking e.g.

if mycontrol.type = actextbox then
mycontrol.enabled = false
mycontrol.locked = true
end if

This can be run from a command button.
 
You don't necessarily have to set the Enabled property to False; doing so prevents the user from selecting and copying the text in the textbox - which may or may not be what you want. At any rate, here's a routine that you could place in the button's click() event:
Code:
Private Sub cmdToggleEdit_Click()
  Dim ctl As Control
  Dim blnLock As Boolean
  
  If cmdToggleEdit.Caption = "&Edit" Then
    cmdToggleEdit.Caption = "&Lock"
    blnLock = False
  Else
    cmdToggleEdit.Caption = "&Edit"
    blnLock = True
  End If
  
  For Each ctl In Me.Controls
    If TypeOf ctl Is TextBox Then
      ctl.Locked = blnLock
    End If
  Next ctl
  
End Sub

VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top