0

I'm using VBA in Microsoft Access for Internet Explorer automation. I've already open the website that I want, but there is an input that when typing the text inside, and pressing enter, the website tries to validate the data and fill other fields based on this input.

Looking at the control I found this code:

      <input name="ctl00$ContentPlaceHolder1$txtId" type="text" maxlength="8" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$txtId\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;
javascript:return ValidateNumber(event);
       " id="ctl00_ContentPlaceHolder1_txtId" class="TextBox" onfocus="javascript:sObjetoOnFocusCSS(this);
       " onblur="javascript:sObjetoOnBlurCSS(this,'TextBox');" 
        style="font-weight:normal;"> 

I think the ValidateNumber(event)is responsible for the Validation of the data inserted in this input to fill other fields in this website.

I tried to do something like Call document.all(ctl00$ContentPlaceHolder1$txtId).fireEvent("ValidateNumber(event)"); but it didn't work.

What can I do or fix to run the ValidateNumber(event) function that Validates the data inside ctl00$ContentPlaceHolder1$txtId control?

tdmsoares
  • 533
  • 7
  • 24

2 Answers2

1

Since there is an onChange event associated with the element, dispatching the event should execute it. Give this a try after you populate the input field.

Dim ie as InternetExplorerMedium
Dim ieEvent
Dim htmldoc as HTMLDocument

Set ie = 'however you're setting IE'
Set htmldoc = ie.document
Set ieEvent = htmldoc.createEvent("HTMLEvents")

ieEvent.initEvent "change", False, True
ie.document.all.Item("ctl00_ContentPlaceHolder1_txtId").dispatchEvent ieEvent
DukeTogo
  • 21
  • 4
0

The script you mention is associated with an onkeypress event so you could try:

htmldoc.querySelector("input[name='ctl00$ContentPlaceHolder1$txtId']").FireEvent "onkeypress"
QHarr
  • 83,427
  • 12
  • 54
  • 101