Results 1 to 4 of 4

Thread: How to Lock Textboxes on Form?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    How to Lock Textboxes on Form?

    hi there,
    i know the command to Lock Editing in Textboxes that is:

    Text1.text.locked = true
    I have more than 60 texboxes on a Form, it is bit head-ech to write above said command for each textbox.
    Is there any method to lock all the textbox on form with single or 2 line cod?
    plz help

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: How to Lock Textboxes on Form?

    Iterate through the controls collection to find all textboxes

    VB Code:
    1. 'Put in a module so it can be called by any form.
    2. Public Sub LockUnlockTextBoxes(Form as Form, Optional ByVal Locked as boolean = True )
    3.    Dim ctl as Control
    4.  
    5.    For each ctl in Form.Controls
    6.         If TypeOf ctl is TextBox Then
    7.             ctl.Locked = Locked
    8.         End If
    9.    Next
    10. End Sub
    11.  
    12. 'sample calls from command buttons on a form
    13. Private Sub cmdLockEm_Click()
    14.     LockUnlockTextBoxes Me
    15. End Sub
    16. Private Sub cmdUnLockEm_Click()
    17.     LockUnlockTextBoxes Me, False
    18. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: How to Lock Textboxes on Form?

    Mr. Brucevde,
    Your code for lock texbox is working (thanx)
    But when i try to unlock them, it wont work... with error message (sub or function not defined)

    my code is here
    ---------------------------------
    Private Sub unlock_Click()
    Dim Password As String
    Dim InputPassword As String
    Password = "code"

    Do
    InputPassword = inputbox("Contact Administrator")

    If InputPassword = Password Then

    LockUnlockTextBoxes Me, False
    txtkrun.SetFocus
    Else
    MsgBox "ACCESS DENIED", vbCritical, "ERROR"
    End If
    End Sub

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to Lock Textboxes on Form?

    That means you have a sub or a function that you are calling that isn't defined.

    It either doesn't exist in your project, or you misspelled the name when you called it. Which one is the error pointing to?

Posting Permissions

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



Click Here to Expand Forum to Full Width