While filling out an online form, new hidden fields become visible depending on the options you have previously chosen.
My question is:
Why do these hidden fields become visible while filling out the form manually (selecting and clicking the mouse in real time) but NOT when filling out programmatically?
To replicate, here is the code. Keep in mind that this is a Dutch form. Before you run the code, first start with selecting "Ja" where the question is "Woont u in Nederland?" Then a new field becomes visible. From that point run the code.
The url is:
https://www.belastingdienst.nl/wps/.../hulpmiddel-motorrijtuigenbelasting-berekenen
My question is:
Why do these hidden fields become visible while filling out the form manually (selecting and clicking the mouse in real time) but NOT when filling out programmatically?
To replicate, here is the code. Keep in mind that this is a Dutch form. Before you run the code, first start with selecting "Ja" where the question is "Woont u in Nederland?" Then a new field becomes visible. From that point run the code.
The url is:
https://www.belastingdienst.nl/wps/.../hulpmiddel-motorrijtuigenbelasting-berekenen
Code:
Option Explicit
Sub Show_Hidden_Field()
'************************************************************
'Hidden field doesn't unhide when previous option is selected
'Set References to:
'Microsoft HTML.Object Library
'Microsoft Forms 2.0 Object Library
'Microsoft Internet Controls
'Accessible via: Alt+F11 | Tools | References
'************************************************************
'Declaration section
Dim IE As New SHDocVw.InternetExplorer
Dim htmlDoc As New MSHTML.HTMLDocument
Dim objShell, objShellWindows, objShellWindow As Object
Dim dd As MSHTML.IHTMLElement
Dim strVehicle As String
'Wait an extra 3 seconds so you can switch to the IE window
'and see what's going on
Application.Wait Now + TimeValue("0:00:03")
'Find the correct IE window
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
For Each objShellWindow In objShellWindows
If objShellWindow.Name = "Internet Explorer" Then
'Find this window
If objShellWindow.LocationURL = "https://www.belastingdienst.nl/wps/wcm/connect/nl/auto-en-vervoer/content/hulpmiddel-motorrijtuigenbelasting-berekenen" Then
'Get the content of page
Set htmlDoc = objShellWindow.document
Exit For
End If
End If
Next objShellWindow
'Find "Vehicle"
strVehicle = "Personenauto"
Set dd = htmlDoc.getElementById("V1-2")
If strVehicle = "Personenauto" Then
dd.Children(1).Selected = True
'**********************************************************************
'dd.Children(1).Click '<---Tried this option also
'dd.Children(1).FireEvent ("onchange") '<---Tried this option also
'set focus to button "Nee"
htmlDoc.getElementById("V1-1_False").Focus '<---Tried this option also
'**********************************************************************
End If
End Sub
Last edited: