Solved

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

Posted on 2014-12-22
4
680 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 34

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

734 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