Get selected option value from combobox on web pâge from access 2013 VBA code

I need to get the values of the selected option!

The web page code is as follows !
                      <td><select name="E_NETWORK_ID" size=1 onChange="setBamUom(this.form, 'E_NETWORK_ID', 'ZPS22')" style="width:260; font-size:11px;"
                                                  <option SELECTED
                                       value="WFO_3RDPAR">Third party app

The code I'm attempting to use is !

           Set divs2 = myBrowser.Document.getElementsByTagName("select")

          For Each el2 In divs2
                  teststr = el2.innerHTML
                  strl = InStr(teststr, "selected")
            If strl > 0 And el2.Name = "E_NETWORK_ID" Then
                 teststr3 = Mid(teststr, strl, 750)
               MsgBox (" Net_info2 = ") & teststr
               strl2 = InStr(teststr3, ">")
             Me.net_info = Mid(teststr, strl2 + 1, 4)  ' this has yet to be adjusted
             MsgBox (" net_info = ") & Mid(teststr3, strl2 + 1, 4) ' same here
         End If
I've tried different combinations and still can't get the right info to show up!

Peter GrovesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:

Are you sure you are grabbing the correct element(s)?

PS If you are grabbing the SELECT element have you tried looking at its selectedindex attribute?

You might be able to use that along with its options collection to determine which item has been picked.
Set divs2 = myBrowser.Document.getElementsByTagName("select")

For Each el2 In divs2
    If = "E_NETWORK_ID" Then Exit For
Next el2

If Not el2 Is Nothing Then
    idx = el2.selectedIndex
    opt = el2.options(idx)
    MsgBox " net_info = " & opt
    MsgBox "Not found!"
End If


Open in new window

Peter GrovesAuthor Commented:
Sorry for the long interval!

I'm not getting the "  getElementsByTagName("select") "  to work.  It always returns blank!

Same method I use for other selects in another page on a different site!

There was a slight error in the above code though didn't help after it was corrected.

myBrowser.Document.getElementsByTagName("select") I added document!

So since I don't detect the select your code didn't work either!

Any suggestions as to an alternative route?


NorieAnalyst Assistant Commented:

I can't see why getElementsByTagName wouldn't work,  is it definitely returning nothing?

Have you tried getElementsByName?
Set divs2 = myBrowser.Document.getElementsName("E_NETWORK_ID")

Open in new window

Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

Peter GrovesAuthor Commented:
Hi ,

  Actiually getElementsByTagName does work as I see

MsgBox (" qname = ") & el.Name    prints out the E_NETWORK_ID .

The problem is that I don't see anything else!  I've looked at the innerHTML  and its blank!

The OuterHTML contains only ! (<SELECT onchange="setBamUom(this.form, 'E_NETWORK_ID', 'ZPS18-ZNET_UOM')" disabled style="FONT-SIZE: 11px; WIDTH: 260px" size=1 name=E_NETWORK_ID></SELECT>)

Peter GrovesAuthor Commented:
For added info , in the actual HTML from the web page I do see  the seleced option that I show in my original entry above. But the odd thing is that there is a lot of blank lines in between options! Hope this provides insight to a solution!


Peter GrovesAuthor Commented:
Hi , Finally found the problem. It was a timing issue. I used the following to wait for stable web page!

     Do While oBrowser.Busy Or oBrowser.ReadyState <> 4
         Debug.Print oBrowser.ReadyState

But for some reason it wasn't working in this section of the web page and I had to insert a manual timing loop
for a second!
Now the data shows up correctly, so you were correct in assuming the code was good!

This worked fine when I first programmed it last year but I believe they updated the web code and caused this error.

Thanks for the responses though!  


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
hi Peter,

glad you got it. Thanks for sharing!

For what its worth, I usually only use DoEvents on occasion such as if keyboard intervention is desired, values are being written to an object such as a form by code that is not behind that form, and lately, to completely load a web page (not in a loop though) so the "more" or whatever link is there gets executed.

As a general rule, I find that DoEvents, being so resource-intense, takes loops way longer to execute -- so using it to wait is counter-productive.  Here is what I use instead ... or just skip the wait time and simply loop till the desired value is obtained.
'declare Sleep API
#If VBA7 Then             '  Code is running in the new VBA7 editor
    Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else                     ' Code is running in VBA version 6 or earlier
   Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If

Public Sub WaitMilliSeconds(nNumMilliseconds As Long)
    Sleep nNumMilliseconds
End Sub

Open in new window

have an awesome day,
Peter GrovesAuthor Commented:
The problem was caused by the web application change and not my code!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.