Peter Groves
asked on
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 !
<code>
<td><select name="E_NETWORK_ID" size=1 onChange="setBamUom(this.f orm, 'E_NETWORK_ID', 'ZPS22')" style="width:260; font-size:11px;"
>
<option SELECTED
value="WFO_3RDPAR">Third party app
</select>
</code>
The code I'm attempting to use is !
<code>
Set divs2 = myBrowser.Document.getElem entsByTagN ame("selec t")
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
Next
</code>
I've tried different combinations and still can't get the right info to show up!
Pete
The web page code is as follows !
<code>
<td><select name="E_NETWORK_ID" size=1 onChange="setBamUom(this.f
>
<option SELECTED
value="WFO_3RDPAR">Third party app
</select>
</code>
The code I'm attempting to use is !
<code>
Set divs2 = myBrowser.Document.getElem
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
Next
</code>
I've tried different combinations and still can't get the right info to show up!
Pete
ASKER
Sorry for the long interval!
I'm not getting the " getElementsByTagName("sele ct") " 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.getElem entsByTagN ame("selec t") I added document!
So since I don't detect the select your code didn't work either!
Any suggestions as to an alternative route?
Thanks
Pete
I'm not getting the " getElementsByTagName("sele
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.getElem
So since I don't detect the select your code didn't work either!
Any suggestions as to an alternative route?
Thanks
Pete
Pete
I can't see why getElementsByTagName wouldn't work, is it definitely returning nothing?
Have you tried getElementsByName?
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")
ASKER
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.f orm, 'E_NETWORK_ID', 'ZPS18-ZNET_UOM')" disabled style="FONT-SIZE: 11px; WIDTH: 260px" size=1 name=E_NETWORK_ID></SELECT >)
Pete
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.f
Pete
ASKER
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!
Thanks
Pete
Thanks
Pete
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
have an awesome day,
crystal
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)
'pause
Sleep nNumMilliseconds
End Sub
have an awesome day,
crystal
ASKER
The problem was caused by the web application change and not my code!
Pete
Pete
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.
Open in new window