+ Reply to Thread
Results 1 to 20 of 20

Disable a command button yet enable it based on other conditions

  1. #1
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Disable a command button yet enable it based on other conditions

    Hello, the attached workbook will open a userform. I am trying to construct an argument that ensures the below takes place:

    1. When a row in the listbox has all three elements(i.e. Number, Item and Type) then the Save command button should be disabled. Therefore if the user is browsing the listbox items row by row by clicking on each row, whenever a fully populated row (with all three elements) is clicked then the save button should show as disabled.

    2. For rows that have elements missing, the Save command button will only be enabled when all three textboxes contain data, then the user can click the save button to save the data.

    So far I am able to achieve only criteria #2 above as you can see. However I am unable to construct the code to achieve criteria #1 and unfortunately when I click on a fully populated row with all three elements, the save command button shows as enabled.

    Would appreciate your help!
    Last edited by chin67326; 12-24-2015 at 05:34 AM.

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Disable a command button yet enable it based on other conditions

    I don't follow, you say that when 3 items are there the save button disabled, but say when 3 items have the save button show? Is No. 1 contradicting No. 2?
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Disable a command button yet enable it based on other conditions

    Quote Originally Posted by JapanDave View Post
    I don't follow, you say that when 3 items are there the save button disabled, but say when 3 items have the save button show? Is No. 1 contradicting No. 2?
    When the listbox shows a row with 3 items (number, item and type) the save button should show as disabled (this means the data is already there and nothing else is needed).

    When the three textboxes are all empty or some are empty, the save button should show as disabled.

    For listbox rows that are missing data, the save button should only come alive and show as enabled when the user has entered data in the textboxes so he can click the button and save the data.

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Disable a command button yet enable it based on other conditions

    Are you saying when the line with 3 items in the LIST box is selected?

  5. #5
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Disable a command button yet enable it based on other conditions

    Quote Originally Posted by JapanDave View Post
    Are you saying when the line with 3 items in the LIST box is selected?
    Yes, selecting any line (or row) of data in the listbox would show the save button as disabled - i.e. whether a line has all the data or some data, when the line is clicked with the mouse and selected, the save button will be disabled.

    However, for a Line (or row) that is missing data, the save button will ONLY be enabled and come alive after the user has inputted data in ALL THREE textboxes, and the user can then click save then the save button will then be disabled.

  6. #6
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Disable a command button yet enable it based on other conditions

    Replace the code for txtType_Change to this,

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    09-28-2014
    Location
    harbin,china
    MS-Off Ver
    2007
    Posts
    162

    Re: Disable a command button yet enable it based on other conditions

    Hi, chin
    try this
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Disable a command button yet enable it based on other conditions

    Quote Originally Posted by JapanDave View Post
    Are you saying when the line with 3 items in the LIST box is selected?
    Yes, selecting any line (or row) of data in the listbox would show the save button as disabled.
    Last edited by chin67326; 12-23-2015 at 10:01 AM.

  9. #9
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Disable a command button yet enable it based on other conditions

    Sorry you will have to use the below if statement on all three text boxes not just the one I stated.

    Please Login or Register  to view this content.

  10. #10
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Disable a command button yet enable it based on other conditions

    Like this
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Disable a command button yet enable it based on other conditions

    Quote Originally Posted by simcode View Post
    Hi, chin
    try this
    Hi simcode, thanks but when I select a line of data from the listbox in your workbook, the save button shows as enabled and therefore one can change data in the textbox and click save and overwrite the data. I will try JapanDave's advice and will let you know if it works.

  12. #12
    Forum Contributor
    Join Date
    09-28-2014
    Location
    harbin,china
    MS-Off Ver
    2007
    Posts
    162

    Re: Disable a command button yet enable it based on other conditions

    Sorry, i haven't noticed it before submit
    try
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Disable a command button yet enable it based on other conditions

    JapanDave, thank you! Your solution is exactly what I need. It worked fine.

    Good day to you!

  14. #14
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Disable a command button yet enable it based on other conditions

    Quote Originally Posted by simcode View Post
    Sorry, i haven't noticed it before submit
    try
    Please Login or Register  to view this content.
    Simcode, that still won't work I believe.

  15. #15
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Disable a command button yet enable it based on other conditions

    Quote Originally Posted by chin67326 View Post
    JapanDave, thank you! Your solution is exactly what I need. It worked fine.

    Good day to you!
    No worries.

  16. #16
    Forum Contributor
    Join Date
    09-28-2014
    Location
    harbin,china
    MS-Off Ver
    2007
    Posts
    162

    Re: Disable a command button yet enable it based on other conditions

    A row in the listbox has all three elements, and you find an element is wrong, you want modify it, what would you do. Now the save button is disabled

  17. #17
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Disable a command button yet enable it based on other conditions

    Quote Originally Posted by simcode View Post
    A row in the listbox has all three elements, and you find an element is wrong, you want modify it, what would you do. Now the save button is disabled
    That is a valid point; in that case the user will have to notify the administrator of that workbook.

  18. #18
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Disable a command button yet enable it based on other conditions

    You could add a modify button with administrator privileges.

  19. #19
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Disable a command button yet enable it based on other conditions

    Quote Originally Posted by JapanDave View Post
    You could add a modify button with administrator privileges.
    Yes, that one I can take care of. Cheers guys!

  20. #20
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Disable a command button yet enable it based on other conditions

    Don't forget to rep those who helped. Cheers.

+ 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. Radio button enable/disable based on data in table
    By oscarmiike in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2015, 01:37 AM
  2. Enable/Disable Radio Button based on table data
    By oscarmiike in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-07-2015, 03:17 AM
  3. [SOLVED] Enable Disable spin button based on a textbox
    By forrestgump1980 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-21-2015, 07:21 AM
  4. [SOLVED] Disable/Enable command button in Excel sheet
    By luneke1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2014, 12:51 AM
  5. enable/disable a command button in User Form w/ condition
    By Bidyut Chakraborty in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2014, 03:11 AM
  6. [SOLVED] Enable/Disable Command Button
    By rain4uu in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-06-2012, 03:27 AM
  7. enable/disable start button on basis of chkbox conditions
    By ilyaskazi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-04-2005, 04:09 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