Solved

on access 2013 web browser control  to submit a username and password?

Posted on 2014-12-22
4
581 Views
Last Modified: 2014-12-23
how can i make with vba  that the web browser control will  put a user name and password on a web form and submit it ?
0
Comment
Question by:bill201
  • 2
4 Comments
 
LVL 32

Assisted Solution

by:ste5an
ste5an earned 250 total points
ID: 40514535
It strongly depends on the web site itself and it's sometimes hard to do. It also depends on what you like to do with it.

Normally credentials for a login are queried by a form. Thus you need to interact with the site using the DOM.

Here is an example showing how to find an input element using early binding, so you need to reference the Microsoft HTML Library:

Option Compare Database
Option Explicit

Private NavigateComplete As Boolean
Private WithEvents m_WebBrowser As SHDocVw.WebBrowser

Private Sub FillAndSubmitForm()

  Dim Element As MSHTML.IHTMLElement
  Dim Elements As MSHTML.IHTMLElementCollection
  Dim InputElement As MSHTML.IHTMLInputElement
  
  Set Elements = m_WebBrowser.Document.getElementsByTagName("input")
  If Not Elements Is Nothing Then
    For Each Element In Elements
      If (TypeOf Element Is MSHTML.IHTMLInputElement) And (Element.Name = "q") Then
        Set InputElement = Element
        InputElement.Value = "Access VBA IE DOM"
        InputElement.Form.submit
      End If
    Next Element
  End If

  Set InputElement = Nothing
  Set Element = Nothing
  Set Elements = Nothing
  
End Sub

Private Sub btnLoadPage_Click()

  NavigateComplete = False
  m_WebBrowser.Navigate2 "google.com"

End Sub

Private Sub ctlWebBrowser_DocumentComplete(ByVal pDisp As Object, URL As Variant)

  If Not NavigateComplete Then
    NavigateComplete = True
    FillAndSubmitForm
  End If

End Sub

Private Sub Form_Load()

  Set m_WebBrowser = ctlWebBrowser.Object

End Sub

Private Sub m_WebBrowser_TitleChange(ByVal Text As String)

  Me.Caption = Text

End Sub

Open in new window


You need to examine your page with the IE dev tools (press F12). Then you can find the appropriate element names or ids.
0
 
LVL 39

Accepted Solution

by:
thenelson earned 250 total points
ID: 40514768
Frequently you can pass the user name / password to the website when you enter the website's URL like this:
    "https://username:password@www.websiteaddress.com/"
This is an internet protocol so it works on many websites.

If that does not work with the website you are interfacing with, you will need to interact with the website as ste5an explains.

Here is a demo database that will show you how to use the webbrowser control and automation to interact with websites:
http://www.thenelson.name/#WebAccess
0
 

Author Closing Comment

by:bill201
ID: 40515884
thanks a lot
0
 
LVL 39

Expert Comment

by:thenelson
ID: 40515941
glad I could help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now