+ Reply to Thread
Results 1 to 5 of 5

Userform Commandbutton does not update on click

  1. #1
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Userform Commandbutton does not update on click

    Greetings,

    I expanded on the code provided here by replacing the "Do...Loop Until" section with a userform. The revised code is Sub UpdateSector.

    When Sub UpdateSector is called, it works fine, ie, displays the userform when input is required; updates the combobox selection / input to the relevant field when the commandbutton is clicked; then closes the userform.

    However if I add any code after the For-Next statement, say eg Msgbox "Test", the combobox selection/ input is updated to the relevant field only after the Msgbox "Test" is displayed.

    Can anyone please help me identify the reason for this behaviour? Below is the entire code (Please bear with me as I do not know which line could be causing the problem) in the standard module

    Please Login or Register  to view this content.
    and code in the userform module

    Please Login or Register  to view this content.
    Let me know if I need to attach a sample file. Many many thanks
    Asha


    Last edited by asha3010; 10-05-2010 at 04:32 AM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Userform Commandbutton does not update on click

    A sample file I suspect would help, but as two general comments:
    1. Avoid public variables. They are often unnecessary, as here.
    2. Don't use the RowSource property (unless you absolutely have to use the column headers). Assign the value of the range you want to the List property of the Combobox.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Userform Commandbutton does not update on click

    Thanks for your reply romperstomper.

    Re your comments:

    1. Avoid public variables. They are often unnecessary, as here.
    Can you please suggest how else I could pass the variable "sResponse" from userform to standard module. I can then work on changing the code.

    2. Don't use the RowSource property (unless you absolutely have to use the column headers). Assign the value of the range you want to the List property of the Combobox.
    I am sure you have a very good reason for saying this - is it because it is not very efficient? I have not used the List property before but I will read it up.

    I have attached a sample file. The macro UpdateSector is called by clicking on the shape in sheetDE_CN. Once the "Ok" button is clicked on the userform, it displays the message box and then populates relevant cells in Col D.

    I don't understand why this happens because it should be the other way round as per the code.

    Thanks a million
    Asha
    Attached Files Attached Files

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Userform Commandbutton does not update on click

    In order:
    1. When using forms, you can set up property procedures so that your code can read the values from the form - this does require you to keep the form hidden rather than unloaded.
    2. If you bind a control to the worksheet, you can find that changes on the sheet trigger events on your form that you weren't expecting or wanting. Since you have no need of a link between the two, there is no benefit to using Rowsource.

    As far as your code goes, it is working in exactly the right order, it's just that you have turned off screenupdating so you see the message box appear first, but the data is actually already present in the sheet.

  5. #5
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Userform Commandbutton does not update on click

    Thanks a lot romperstomper for your prompt response & explanation.

    I didn't realise it was the screenupdating - thanks for spotting it!

    1. I will give this a go.
    2. Have already used your recommendation of ListProperty.

    Thanks again
    Asha

+ 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