+ Reply to Thread
Results 1 to 9 of 9

"If" dropdown result changes "then" VBA

  1. #1
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    "If" dropdown result changes "then" VBA

    Hello everyone,

    I have a dropdown (bookmark: Country_Name) and a text box (bookmark: txtState) in my Word 2003 document.
    The text box, when selected, has a macro which opens a userform.
    The userform has the following code:

    Please Login or Register  to view this content.
    The code is from the following website:
    http://gregmaxey.mvps.org/word_tip_p...own_lists.html

    This code fills the ListBox in the userform depending on the selection in the dropdown box.

    What I would like is a code which clears the textbox whenever the selection in the dropdown changes.
    Now, whenever a dropdown and textbox selection is made and the dropdown selection is changed the textbox still has a value, which is wrong in that case.

    Kind regards,

    Marco

  2. #2
    Registered User
    Join Date
    06-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: "If" dropdown result changes "then" VBA

    Dear,


    In dropdown changes Event()

    add the code at the beginning
    PHP Code: 
    textbox_name.value "" 

  3. #3
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: "If" dropdown result changes "then" VBA

    I'm not really sure where to put this code. Do you mean in the VBA I posted above, in the userform?

    Is the event "Sub DropdownChange"? or something like that?

    Marco
    Last edited by Marco-Kun; 06-15-2012 at 08:56 AM.

  4. #4
    Registered User
    Join Date
    06-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: "If" dropdown result changes "then" VBA

    go to form.
    select the list box or combo box .
    double click the Drop down button on the form for whose change in value will make the text box blank.
    VBA window will open


    on right side of the window u will find a drop down select the change from this drop down.


    2 new lines will be added

    which will be like

    public sub (list box or combo box)_change()



    end sub


    paste My code between these 2 lines then replace the control name in my code with actual text box name.


    This code will run when ever u change the dropdown box.

  5. #5
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: "If" dropdown result changes "then" VBA

    Dear Md Aejaz,

    Thanks for that explanation. I was aware of how to do that though.
    The difference is that the dropdown and the textbox aren't on the form.

    I added an example for you to see.

    In the first dropdown you select a country. When you click the second box, the userform opens where you select a Province.

    When this is done, when the first dropdown selection changes, I want the second box to clear.

    Thanks in advance,

    Marco
    Attached Files Attached Files

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: "If" dropdown result changes "then" VBA

    Simply add the following 'on exit' macro to your dropdown's properties:
    Please Login or Register  to view this content.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  7. #7
    Registered User
    Join Date
    01-05-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: "If" dropdown result changes "then" VBA

    Hi guys,

    I am trying to complete a dropdown event where if a certain word from the dropdown list is selected the colour of the word changes to red? How can I go about doing this?

    regards,
    Mykie

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: "If" dropdown result changes "then" VBA

    Hi Mykie,

    You really should start a new thread for this and not hijack an existing thread that deals with a different issue.

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: "If" dropdown result changes "then" VBA

    Hello mykie.

    Unfortunately you have inadvertently broken one of the forum rules. Please read the following and make the necessary change. Thanks.

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

+ 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