VBA: How to input date in an Internet Explorer search field

ExcelRooky91

New Member
Joined
Apr 3, 2018
Messages
10
Hi All,

I'm grinding away at my first attempt at writing a code and I'm struggling with trying to input a date in a search field box. My current code results in runtime error 13: Type mismatch.

Anyone more experienced able to shed some light for me?

Kind regards,
Ty

The Website I'm accessing is: https://www.nzfma.org/data/search.aspx

My current code is:

Code:
Sub BKBM_Rates()
'This will load a webpage in IE
    Dim i As Long
    Dim URL As String
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object
       
    'Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")
 
    'Set IE.Visible = True to make IE visible, or False for IE to run in the background
    IE.Visible = True
 
    'Define URL
    URL = "[URL]https://www.nzfma.org/data/search.aspx[/URL]"
 
    'Navigate to URL
    IE.Navigate URL
   
   'make sure the page is done loading
       Do
DoEvents
Loop Until IE.ReadyState = 4

    'attempting to search date based on date value in cell
Dim inputfield As HTMLInputElement
Set inputElement = IE.document.getElementById("ct100_cphBody_rdpDate_dateInput")
If inputfield.Type = "text" Then inputfield.Value = Sheets("Sheet1").Range("b2").Value
   
    'clicking the search button
IE.document.getElementById("cphBody_btnSearch").Click
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I have tweaked the code to the following but the search result shows[h=3]"Bank Bill Reference Rates Report for 1 Jan 0001[/h]No data available"

I feel there is something to do with a hidden date entry aswell? Any help is appreciated.


Code:
Sub BKBM_Rates()
'This will load a webpage in IE
    Dim i As Long
    Dim URL As String
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object
       
    'Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")
 
    'Set IE.Visible = True to make IE visible, or False for IE to run in the background
    IE.Visible = True
 
    'Define URL
    URL = "[URL]https://www.nzfma.org/data/search.aspx[/URL]"
 
    'Navigate to URL
    IE.Navigate URL
   
   'make sure the page is done loading
       Do
DoEvents
Loop Until IE.ReadyState = 4
    'attempting to search date based on date value in cell
IE.document.getElementById("ctl00_cphBody_rdpDate_dateInput").Value = Sheets("Sheet1").Range("B2")
   
    'clicking the search button
IE.document.getElementById("cphBody_btnSearch").Click
End Sub
 
Upvote 0
How would you enter the date manually on the site?

Would you type it directly or would you use some sort of date picker?
 
Upvote 0
Most date pickers can be used without activating the pop up as long as you press Enter after manually putting the date in the box with the expected format.
So we enter the date, select the date box then send the ENTER key.
Entry and selection can be either way around.

I put a delay in prior to searching also. It works without both delays but hasn't had a lot of testing.

The following works for me:
Code:
'attempting to search date based on date value in cell
IE.document.getElementById("ctl00_cphBody_rdpDate_dateInput").Value = Sheets("Sheet1").Range("B2").Text

'Select the date picker box and press Enter to 'activate' the new date
IE.document.getElementById("ctl00_cphBody_rdpDate_dateInput").Select
 
Application.Wait (Now() + TimeValue("00:00:01"))
SendKeys "+{ENTER}"


'clicking the search button
Application.Wait (Now() + TimeValue("00:00:03"))
IE.document.getElementById("cphBody_btnSearch").Click
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top