Hello everyone!
I have looked through these forums for help in the past, but I have not been able to find any thread or website that details my specific issue. I'm hoping those with more knowledge regarding VBA can assist me, as I am somewhat new (and self-taught) to VBA.
I have a website that I am looking to control through VBA. This website is a website that ends in .asp (not sure if that matters). I have the website load through a WebBrowser control through Access, but when I try to click on a button on the website, I am presented with the following error:
Run-time error '91':
Object variable or With block variable not set
I have been able to load the Google homepage and click on the Sign In button with the same WebBrowser control and code, so I am unsure of what I am doing wrong.
The following references have been added to my database:
- Visual Basic for Applications
- Microsoft Access 14.0 Object Library
- OLE Automation
- Microsoft Office 14.0 Access database engine Object Library
- Microsoft Internet Controls
- Microsoft Outlook 14.0 Object Library
- Microsoft Scripting Runtime
- Microsoft Office 14.0 Object Library
- Microsoft HTML Object Lubrary
- Microsoft_JScript
Rather than having the code execute in the WebBrowser control, I created a command button that I can click on to execute the code when the page is completely loaded. That way I can ensure that the element is fully loaded before executing code in case that causes an error. This code has been put in a command button next to the WebBrowser control:
Code:
Dim HTML As HTMLDocument
Dim btn As HTMLButtonElement
Dim btn2 As HTMLInputElement
Set HTML = Forms("My_Form").WebBrowser0.Object.document
With HTML
Set btn = HTML.getElementById("ClearButton")
btn.Click
End With
I have tried using btn2 in place of btn (HTMLButtonElement vs. HTMLInputElement), and have tried moving the Set btn to before the With statement. No matter what I try on the webpage, it gives the error above.
The webpage in question has the following code:
Code:
<input name="ClearButton" tabIndex="11" class="ButtonStyle" id="ClearButton" type="submit" SIO="[object Object]" value="Clear"></input>
If I right-click and click on "Edit as HTML", the following code shows:
Code:
<INPUT tabIndex=11 id=ClearButton class=ButtonStyle type=submit value=Clear name=ClearButton>
I would greatly appreciate any assistance anyone would be able to provide.
Thank you in advance!