+ Reply to Thread
Results 1 to 9 of 9

Disable Textbox1 if Textbox2 is populated

  1. #1
    Registered User
    Join Date
    03-02-2015
    Location
    France
    MS-Off Ver
    2007
    Posts
    4

    Disable Textbox1 if Textbox2 is populated

    Hello!

    I've have been working on a form for about a week.

    My problem is that I can't get to work a simple lock on a Textbox if another Textbox is filled and, the other way around.

    Does anybody know how to do this, it would make my day.

    Don't hesitate if you need any more information.

    Sphax, a friendly IT bloke.
    Last edited by Sphax; 03-25-2015 at 11:48 AM.

  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
    48,204

    Re: Disable Textbox1 if Textbox2 is populated

    Please Login or Register  to view this content.

    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
    Registered User
    Join Date
    03-02-2015
    Location
    France
    MS-Off Ver
    2007
    Posts
    4

    Re: Disable Textbox1 if Textbox2 is populated

    Thank you for your answer,

    It works, but what if the user does a mistake, writes in textbox1 (=>textbox2 locked) but actually wants to write in textbox2.

    For the moment that code line will not reset once you write in a textbox and delete the value.

    Is there a way to get that working?

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Disable Textbox1 if Textbox2 is populated

    use textbox_change event of each textbox.
    the quick and dirty approach - you can create textbox_change sub for each textbox (as you have only two_ not much of a work)
    more general approach would be to create custom class. However this is worth the efforts if you have more controls that you want to handle the same way.

    EDIT: sorry, TMS :-) I've got a phone call before I submit my answer
    If you are pleased with a member's answer then use the Star icon to rate it.

  5. #5
    Registered User
    Join Date
    11-25-2011
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    53

    Re: Disable Textbox1 if Textbox2 is populated

    Quote Originally Posted by Sphax View Post
    Thank you for your answer,

    It works, but what if the user does a mistake, writes in textbox1 (=>textbox2 locked) but actually wants to write in textbox2.

    For the moment that code line will not reset once you write in a textbox and delete the value.

    Is there a way to get that working?
    If you still need help on this you just need to expand TMS's code slightly to enable textbox2 if the value of textbox1 is not ""

    Please Login or Register  to view this content.

  6. #6
    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
    48,204

    Re: Disable Textbox1 if Textbox2 is populated

    diberlee has provided a working solution (thanks for picking up)

  7. #7
    Registered User
    Join Date
    03-02-2015
    Location
    France
    MS-Off Ver
    2007
    Posts
    4

    Re: Disable Textbox1 if Textbox2 is populated

    That's right, just tested the solution and it works like a charm.

    Thank you all guys, always nice to have a place to find some answers.

    THREAD SOLVED

  8. #8
    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
    48,204

    Re: Disable Textbox1 if Textbox2 is populated

    You're welcome. Thanks for the rep.




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  9. #9
    Registered User
    Join Date
    03-02-2015
    Location
    France
    MS-Off Ver
    2007
    Posts
    4

    Re: Disable Textbox1 if Textbox2 is populated

    The little Star is already marked on every person involved in the thread

    I was looking for that option "Solved" thanks for the info.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] error if no value in textbox1 or textbox2
    By James__S in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-06-2015, 09:04 AM
  2. [SOLVED] Userform Textbox1 = Val(Textbox2.Value) / 2
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-14-2013, 09:37 AM
  3. [SOLVED] Cell Value = TextBox1.Value + TextBox2.Value
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-25-2013, 09:30 AM
  4. [SOLVED] textbox1 * textbox2 = textbox3
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-23-2012, 03:35 PM
  5. [SOLVED] TextBox1 = TextBox2
    By Anto_BT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2012, 03:34 AM

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