Solved

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

Posted on 2014-12-22
4
603 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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Direct Mail software 4 42
Run Time Error 3075 15 43
fso.FolderExists("\\server\HiddenFolder$") 4 49
Set email body to html using vbscript 6 24
#Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

912 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

17 Experts available now in Live!

Get 1:1 Help Now