Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    35
    Rep Power
    12

    Question Locking and unlocking text boxes with code


    I have a few textboxes that I need to set locked and greyed out and I need to also be able to change that with a command button. So what I need is for the user to see the information but not be able to change it. when the add button is clicked the user needs to be able to enter the information. Then when the update button is clicked it needs to lock the information back and grey it out. Is this possible to do. I am not sure how to code this. If anyone could show me how to do this with code it would be very helpful.

    Let me thank you in advance for any help.
  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    Code:
    Private Sub addButton_Click()
        Me.txtSomeField.Enabled=True
    End Sub
    
    Private Sub updateButton_Click()
        Me.txtSomeField.Enabled=False
    End Sub
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    35
    Rep Power
    12
    Will this also grey them out as well
  6. #4
  7. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    The text in it will be greyed out. If you want to have the field itself greyed out then you will have to set the backcolor property also.
    i.e.
    Code:
    Private Sub addButton_Click()
        Me.txtSomeField.Enabled=True
        Me.txtSomeField.BackColor=vbWhite
    End Sub
    
    Private Sub updateButton_Click()
        Me.txtSomeField.Enabled=False
        Me.txtSomeField.BackColor=RGB(200,200,200)
    End Sub
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    35
    Rep Power
    12

    Thumbs up


    Thank you for your help.
  10. #6
  11. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    Not a problem
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    35
    Rep Power
    12
    I need one more thing is there a way to keep the text black and not grey so it can be read
  14. #8
  15. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    Just adjust the background color so that the grey is lighter
    i.e. something like RGB(225, 225, 225)

    You can also set the text to bold.
    Last edited by Onslaught; June 27th, 2003 at 12:48 PM.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    35
    Rep Power
    12
    I guess when you set the enable fuction to false It greys the text to. So I will play with it and see if I can make it where it will be viewable. Thanks again for your help. One more thing where can I find the Color skeem numbers.
  18. #10
  19. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    here is something that I found through google
    http://www.hypersolutions.org/pages/rgbdec.html
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    35
    Rep Power
    12

    Thumbs up


    Thank You for spending the time.
  22. #12
  23. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    Your welcome
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2002
    Posts
    693
    Rep Power
    26
    You can also also set the text box to be read/only via an api. this then allows them to cut/copy from it without disabling. Let me know if you would like the code.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    35
    Rep Power
    12
    That would be cool I would like for the user to be able to do that.
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2002
    Posts
    693
    Rep Power
    26
    ok, here's the code although I just realized that it has been superseded by the .locked property, we must still have this remnant from older versions of VB. It still won't grey the text you'll have to do that manually.
    PHP Code:
    Option Explicit
    Const WM_USER = &H400
    Const EM_SETREADONLY = (WM_USER 31)

    Private Declare Function 
    SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As LongByVal wMsg As LongByVal wParam As LonglParam As Any) As Long

    Sub control_readOnly
    (meCtrl As ControlByVal readOnlyFlag As Long)

        
    Dim rc As Long

        On Error Resume Next
        rc 
    SendMessage(meCtrl.HwndEM_SETREADONLYreadOnlyFlag0&)
        
    meCtrl.Locked = (readOnlyFlag <> False)
        
    On Error GoTo 0
    End Sub 
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo