+ Reply to Thread
Results 1 to 12 of 12

Locking a Textbox in a userform when the cell contains data

  1. #1
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    316

    Locking a Textbox in a userform when the cell contains data

    Hi I have created a userform and what i would like to do is lock Textbox 27 but only if data is contained in here, basically I do not want users to be able to change this information once entered. Can this be done and if so can you please help me be ableto do thi.

    All help very much appreciated.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,763

    Re: Locking a Textbox in a userform when the cell contains data

    Maybe set .Enabled = False


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    316

    Re: Locking a Textbox in a userform when the cell contains data

    Ah thought it might be easier than i had thought, would this allow the user to input if the cell was empty.

    Thansk for responding.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,763

    Re: Locking a Textbox in a userform when the cell contains data

    No, you'd need to disable the textbox after it has accepted input.


    Regards, TMS

  5. #5
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    316

    Re: Locking a Textbox in a userform when the cell contains data

    Thanks for replying TMS, i have different users using the form which means disabling the textbox is not going to give me what i needed.

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Locking a Textbox in a userform when the cell contains data

    If the userform is modal they will not be able to input anything to the cell until the userform is closed. Changing the property TMS suggested above will prevent them from changing the value of the textbox.

    I'm afraid I don't understand the question very well. Is that not what you were trying to do?

  7. #7
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    316

    Re: Locking a Textbox in a userform when the cell contains data

    Hi Sorry i am new to VBA and Userforms so probably havent explained myself clearly.

    I have a userform which users can enter new information or update existing information it is used by multiple users and the information is tansferred to another spredsheet. What i want is for Textbox 27 to be locked if it is not blank, basically the user will constatnty update the data as it changes however there is 1 cell which i do not want to change and that is textbox 27. i cant disable it though as a new user will initially need to populate the information. I somehow need code that says if this cell (Column 51) is not blank disable box. An extract of the code is below, its referencing whatever is in combobox 1 and finding the data.
    Please Login or Register  to view this content.
    Theres more lines of code but for ease i have attached the line i need help with.

    hope this makes sense.

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Locking a Textbox in a userform when the cell contains data

    if you are populating the textbox in code you can simply disable it after you populate it or is there more to the issue?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  9. #9
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    316

    Re: Locking a Textbox in a userform when the cell contains data

    Hi Joseph, It wont always be populated by the code if its a new entry the user will need to populate the textbox for the first time with the information.

    So for example a user enters new information by accessing the form and filing in all the textboxes/combobox slections. Next time month they will be updating the entry so will select their name from the checkbox 1 and all the information will be prepopulated (as per the above code) however, they may need to change some of the information such as sales figures but i do not want them to be able to update textbox 27 if its already filled. The userform is for capturing new data and updating. Hope that makes sense. I think i need code that says if cell blank then textbox 27 enabled = true, i do not know how to write it though.

    thanks for helping

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Locking a Textbox in a userform when the cell contains data

    I reckon a sample workbook would make this a lot clearer but perhaps you just need
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    316

    Re: Locking a Textbox in a userform when the cell contains data

    Dear Joseph,

    Thats exactly what i was looking for I have just added it and it works perfectly, thanks so much for your help. You are a genius!

  12. #12
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Locking a Textbox in a userform when the cell contains data

    you're welcome :-)

    please don't forget to mark the thread solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1