Link to home
Start Free TrialLog in
Avatar of HugoMuller
HugoMullerFlag for Netherlands

asked on

How to use HtmlElementCollection in MS-Access 2007

HI,

I am using MS-Access 2007 and have created a form with some fields and the Microsoft Webbrowser object.
When loading the form, I have written code so a webpage is automatically loaded in the control. So far no problems.

I want to write some code to automatically login in the webpage that is loaded in the webbrowser control.
I found some code on the web, but I get an error:

        ' Part 2: Automatically input username and password
        Dim theElementCollection As HtmlElementCollection
        theElementCollection = WebBrowser8.Document.GetElementsByTagName("input")
        For Each curElement As HtmlElement In theElementCollection
           
            Dim controlName As String = curElement.GetAttribute("name").ToString
            If controlName = "UserNameTextBox" Then
                curElement.SetAttribute("Value", "Username text here")
            ElseIf controlName = "PasswordTextBox" Then
                curElement.SetAttribute("Value", "Password text here")
               
                'In addition,you can get element value like this:
                'MessageBox.Show(curElement.GetAttribute("Value"))
            End If
        Next

        ' Part 3: Automatically clck that Login button
        theElementCollection = WebBrowser8.Document.GetElementsByTagName("input")
        For Each curElement As HtmlElement In theElementCollection
            If curElement.GetAttribute("value").Equals("Login") Then
                curElement.InvokeMember ("click")
                ' javascript has a click method for you need to invoke on button and hyperlink elements.
            End If
        Next

When I compile the code, MS-Access tells me there is a syntax error. Also the line starting at "For Each curElement As HtmlElement In theElementCollection" is red.
I have set a reference to the HTML object library.

Who can help, other suggestions/code are welcome !

Thanks, Hugo
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HugoMuller

ASKER

You're right, this code was designed for .NET.
I was just wondering if it could work in Access as well.
And if not, is there another solution.
Not that I know of.

AFAICT, this Class is only available for .net framework development platforms.

Can you tell me how you are trying to apply this to MS Access?

Perhaps there is way to do the same thing in the Access VBA object model...
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.