Web Browser Submit Form VBA

Hi

I am currently displaying a web page through access 2010 using a web browser control.  So far I can enter the username and password but I cannot work out how to click the submit button.  The button has no id but it has an input type = submit and a value ="Submit".

Dim HTMLDoc As MSHTML.HTMLDocument
Dim webControl As WebBrowser
Dim element As Object


Set webControl = wbTickets.Object

With webControl
    .Navigate "http://www.test.org.uk"
End With

Pause (1)

Set HTMLDoc = webControl.Document

Set element = HTMLDoc.getElementById("usermenu")

If element Is Nothing Then

    Pause (1)
    
    HTMLDoc.getElementById("loginemail").Value = "test@test.org"
    HTMLDoc.getElementById("loginpassword").Value = "1234"
End If

Open in new window


I have tried the code below - which doesn't work

For Each element In HTMLDoc.links
    If element.innerText = "Submit" Then
        Call element.Click
        Exit For
    End If
Next element

Open in new window


Any help greatly appreciated

Thanks
Lisa BAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ess KayEntrapenuerCommented:
0
Ess KayEntrapenuerCommented:
This question has been answered here: http://www.experts-exchange.com/Database/MS_Access/Q_28585361.html


hope that helps
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lisa BAuthor Commented:
Hi

Thanks for the reply - starting to get a bit lost here when I try the code myself

'  Dim Element As MSHTML.IHTMLElement
'  Dim Elements As MSHTML.IHTMLElementCollection
'  Dim InputElement As MSHTML.IHTMLInputElement
'
'  Set Elements = HTMLDoc.getElementsById("adminlogin")
'  If Not Elements Is Nothing Then
'    For Each Element In Elements
'      If (TypeOf Element Is MSHTML.IHTMLInputElement) And (Element.Name = "loginemail") Then
'        Set InputElement = Element
'        InputElement.Value = "test@test.org"
'        'InputElement.Form.submit
'      End If
'    Next Element
'  End If
'
'  Set InputElement = Nothing
'  Set Element = Nothing
'  Set Elements = Nothing

Open in new window


I have changed the code to getElementById("adminlogin") this is the form id.  I changed the Element.Name = "loginemail" as this is the name of my login email input.  I have commented out the InputElement.Form.Submit to try and get the email populated first but when I run this I am getting the error object doesn't support this property or method.

The problem is I dont really understand the code - Is the second if statement saying give me all elements that have the input tag and if the element.name = loginemail then assign it the value of test@test.org.  If I was populating a password as well would I have to duplicate the second if statement again and then place the line InputElement.Form.submit below the two if statements like below?

If (TypeOf Element Is MSHTML.IHTMLInputElement) And (Element.Name = "loginemail") Then
        Set InputElement = Element
        InputElement.Value = "test@test.org"

If (TypeOf Element Is MSHTML.IHTMLInputElement) And (Element.Name = "loginpassword") Then
        Set InputElement = Element
        InputElement.Value = "1234"
        InputElement.Form.submit

Open in new window


Any ideas on where I am going wrong?  Thanks
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Lisa BAuthor Commented:
sorry please ignore the comments in the first block of code only line 11 should be commented out
0
Ess KayEntrapenuerCommented:
hatd to say.  please post the web page source code here
0
Lisa BAuthor Commented:
Hi

I have just realised after I posted the comment that the setElements line is getting all the input tags - there are three of these on my form login, password and submit button.

I have amended the code to

Dim HTMLDoc As MSHTML.HTMLDocument
Dim webControl As WebBrowser
Dim obj As Object
Dim Element As MSHTML.IHTMLElement
Dim Elements As MSHTML.IHTMLElementCollection
Dim InputElement As MSHTML.IHTMLInputElement

Set webControl = wbTickets.Object

With webControl
    .Navigate "https://www.test.org"
End With

Pause (1)

Set HTMLDoc = webControl.Document

Set obj = HTMLDoc.getElementById("usermenu")

If obj Is Nothing Then

Set Elements = HTMLDoc.getElementsByTagName("input")
  If Not Elements Is Nothing Then
    For Each Element In Elements
      If (TypeOf Element Is MSHTML.IHTMLInputElement) And (Element.Name = "loginemail") Then
        Set InputElement = Element
        InputElement.Value = "test@test.org"
      End If
      If (TypeOf Element Is MSHTML.IHTMLInputElement) And (Element.Name = "loginpassword") Then
        Set InputElement = Element
        InputElement.Value = "1234"
      End If
      If (TypeOf Element Is MSHTML.IHTMLInputElement) And (Element.Value = "Submit") Then
        Set InputElement = Element
        InputElement.Click
     End If
    Next Element
  End If

  Set InputElement = Nothing
  Set Element = Nothing
  Set Elements = Nothing

Open in new window


This works perfectly - thanks for pointing me in the right direction
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.