Filling an Onchange Combobox [+HELP]-VBForums
Results 1 to 7 of 7

Thread: Filling an Onchange Combobox [+HELP]

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    9

    Filling an Onchange Combobox [+HELP]

    Hello,



    I am filling this form on a Intranet website that has textboxes and comboboxes.
    The code is working fine until now.


    However, there is a combobox that "depends" on another combobox.
    That is, the second combobox is activated after the first one has an option selected. Through researches, I think it's a Combobox Onchange . Not sure, please correct me if I am wrong.

    The thing is, I am being able to populate the first combobox, but the second one does not present any options besides "Select". Even after running the Macro, if click manually in the second combobox, it does not show any options but Select in the list.


    How can I choose an option from a Onchange Combobox ?



    Here's my code so far..


    Code:
      
    Sub AcessaPagina()Dim ie As InternetExplorer
    Set ie = New InternetExplorer
    
    ie.Navigate "http://epmo.intranet.com//Webforms/TaskCreation.aspx"
    
    Do 'Wait till the edit page is loaded.
    Loop Until ie.ReadyState = READYSTATE_COMPLETE And Not ie.Busy
    
    
    ie.Document.getElementById("Content_TEXT_ALPHA_COLUMN1").Value = "COMPANY"
    ie.Document.getElementById("Content_TEXT_ALPHA_COLUMN2").Value = "COMPUTER"
    ie.Document.getElementById("Content_TEXT_ALPHA_COLUMN14").Value = "5555"
    ie.Document.Forms(0).Item("Content_ddlRegion").Value = "28"
    ie.Document.Forms(0).Item("Content_ddlSubRegion").Value = "33"
    ie.Document.Forms(0).Item("Content_ddlPriority").Value = "23"
    ie.Document.Forms(0).Item("Content_ddlActivity").Value = "13720"
    ie.Document.Forms(0).Item("Content_ddlClientCode").Value = "37"
    ie.Document.Forms(0).Item("Content_ddlCompanyCode").Value = "62"
    ie.Document.Forms(0).Item("Content_DDL_COLUMN1").Value = "5978"
    ie.Document.Forms(0).Item("Content_DDL_COLUMN2").Value = "5966" 
    
    ie.Visible = True
    
    End Sub


    And here is part of the code from the Website..


    Code:
    
        Activity :
                        </td>
                        <td style="width: 160px;" align="left">
                            <select name="MasterPage$Content$ddlActivity" onchange="javascript:setTimeout('WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;MasterPage$Content$ddlActivity&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))', 0)" id="Content_ddlActivity" tabindex="14" title="Classification of submitted request." class="DROPDOWNLIST_CLASS" style="width:150px;">
      <option selected="selected" value="0" Title="--Select--">--Select--</option>
      <option value="13718" Title="COR">COR</option>
      <option value="4339" Title="1">Order 1</option>
      <option value="13720" Title="2">Order 2 </option>
      <option value="13719" Title="2">Order 3</option>
     
     </select>
                            <span id="Content_rfvddlActivity" style="color:Red;display:none;">*</span>
                        </td>
                        <td style="width: 160px;" align="right">

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,012

    Re: Filling an Onchange Combobox [+HELP]

    search in this or the vb6 forums for fireevent, i have posted examples previously
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    9

    Re: Filling an Onchange Combobox [+HELP]

    Quote Originally Posted by westconn1 View Post
    search in this or the vb6 forums for fireevent, i have posted examples previously
    Thank you Westconn1 !

    I used....

    Code:
     ie.Document.Forms(0).Item("Content_ddlActivity").Focus
    ie.Document.Forms(0).Item("Content_ddlActivity").Value = "13720"
    ie.Document.Forms(0).Item("Content_ddlActivity").FireEvent ("onchange")

    ... and now the Onchange field shows all options for me to choose.

    However, in the webpage's source code its not possible to find any values besides the "Select" one as per below:

    Code:
    Sub-Activity :
                        </td>
                        <td style="width: 160px;" align="left">
                            <select name="MasterPage$Content$ddlSubActivity" id="Content_ddlSubActivity" tabindex="15" title="Classification type of submitted request." class="DROPDOWNLIST_CLASS" style="width:150px;">
    		<option value="0" Title="--Select--">--Select--</option>
     
    	</select>
                            <span id="Content_rfvSubActivity" style="color:Red;display:none;">*</span>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="width: 200px;">


    Is this normal?? In the Source, all the others fields have lots of values except this one.



    Thanks for the help!

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    9

    Re: Filling an Onchange Combobox [+HELP]

    Nevermind, I found the values performing a search in the developer tools!

    So, now I have ...

    Code:
    ie.Document.Forms(0).Item("Content_ddlActivity").Focus
    ie.Document.Forms(0).Item("Content_ddlActivity").Value = "13720"
    ie.Document.Forms(0).Item("Content_ddlActivity").FireEvent ("onchange")
    
    
    ie.Document.Forms(0).Item("Content_ddlSubActivity").Value = "13735"

    ... BUT the field is not being filled.
    Is there something I have to put after the FireEvent before putting the ie.Document.Forms(0).Item("Content_ddlSubActivity").Value = "13735"
    ??


    Thanks!!

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,012

    Re: Filling an Onchange Combobox [+HELP]

    values for a dropdown list have to be in the list for the dropdown list, this can be written /rewritten at runtime, but only listed values can be inserted, they do not need to be in the page source

    Is there something I have to put after the FireEvent before putting the
    you have to wait for the page to load the list, i am not sure if the ie will be busy or if readystate will change during the loading of the dropdown, you may have to test, else just put some delay loop for however long seems appropriate
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2013
    Posts
    9

    Re: Filling an Onchange Combobox [+HELP]

    Quote Originally Posted by westconn1 View Post
    values for a dropdown list have to be in the list for the dropdown list, this can be written /rewritten at runtime, but only listed values can be inserted, they do not need to be in the page source

    you have to wait for the page to load the list, i am not sure if the ie will be busy or if readystate will change during the loading of the dropdown, you may have to test, else just put some delay loop for however long seems appropriate

    Thanks again, Westconn1..

    I got it with

    Code:
    While ie.Busy
    DoEvents
    Wend
    Application.Wait Now() + TimeValue("00:00:03")


    The thing is, I want the macro to run in the current Internet Explorer window instead of opening a new window everytime.
    Is it possible?
    Last edited by The World Is Yours; Aug 12th, 2013 at 02:35 PM.

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,012

    Re: Filling an Onchange Combobox [+HELP]

    Is it possible?
    yes, internet explorer windows are members of the shell windows collection

    Code:
    set sh = createobject("shell.application")
    msgbox sh.windows.count & " open shell windows"   ' not required
    for each w in sh.windows
       ' test here for internet explorer, then run code
    next
    if you put a reference to shell you can use early binding, as there can be many open shell windows, you will have to find some specific criteria to identify the correct window
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.