Results 1 to 4 of 4
  1. #1
    CWezo10 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2016
    Posts
    2

    Error with controlling a webpage with VBA

    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!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    It is hard to determine what the issue is. The first thing that jumps out is I am not seeing any code that is verifying the webpage has finished loading. Another thing is you need to make sure you have the correct element and element type. For instance, something named ClearButton may not be the actual element you think it is. So maybe Edit tools or iterating and enumerating the elements with VBA is necessary.

    Some times it is not a button click you need to do but you need to execute a function.

    Maybe this code will help a little
    https://www.accessforums.net/showthr...465#post246465

  3. #3
    CWezo10 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2016
    Posts
    2
    Thank you for that link. I won't be able to try it out until Monday as it is on a workstation at work, but I'll reply and let you know if it works. If I am incorrectly identifying the object when I "Dim As HTMLButtonElement", are you aware of a way that I could have the VBA identify the element or create a list of all the elements, their IDs, and their classifications? I'm wondering if I am just telling the VBA to look for a HTMLButtonElement where instead it should be looking for another type of object, resulting in the error. Do you think that is possible?

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    The link I provided is just about all I am willing to share publicly. Someone should be able to figure it out using the information I have provided. However, they would have to already know something about programming and will likely have a specific business purpose for doing so.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Publishing a database on my webpage
    By DONCOR in forum Import/Export Data
    Replies: 5
    Last Post: 08-29-2014, 09:29 AM
  2. Replies: 1
    Last Post: 11-27-2012, 08:40 AM
  3. Replies: 1
    Last Post: 04-01-2011, 01:28 PM
  4. Controlling autonumber
    By Patience in forum Access
    Replies: 3
    Last Post: 06-22-2010, 04:11 AM
  5. Exporting Form in Access to Webpage
    By StarrySky in forum Forms
    Replies: 0
    Last Post: 03-14-2010, 11:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums