Log In To Website Using UserID and Password

N

Neil

I have an Access database that has user IDs and passwords for different
accounts. I need to be able to log into a web site using a user ID and
password from the database, so that payments can be made for the account.
The web site being logged into is:

https://customersupport.dishnetwork.com/customercare/prepLogon.do

Is there a way to run code from Access that can perform a log-in using a
user's ID and password?

Thanks!
 
B

BobAlston

I have an Access database that has user IDs and passwords for different
accounts. I need to be able to log into a web site using a user ID and
password from the database, so that payments can be made for the account.
The web site being logged into is:

https://customersupport.dishnetwork.com/customercare/prepLogon.do

Is there a way to run code from Access that can perform a log-in using a
user's ID and password?

Thanks!
You could probably use IMacros, a scripting system, to do that. I have
used it previously, starting it from Access.

Bob
 
N

Neil

BobAlston said:
You could probably use IMacros, a scripting system, to do that. I have
used it previously, starting it from Access.

Bob

Thanks. I'll look into that.
 
N

Neil

Probably something like:

Set htm = WebBrowser1.Document
Set frms = htm.Forms(0)
htm.Forms(0).submit


That didn't work - actually just ran Search in the web browser. LOL

But I actually found a different solution which, while not elegant, works
great, and is actually better for the client.

I placed the Access 2010 Web Browser control in the form where the user ID
and password are stored. I then use it to navigate to the login page, and
then use SendKeys to send the user ID, password, and click the Login button,
using a combination of Tabs and Enter.

Since I control the environment, and am not switching away to another
window, using SendKeys works great. Just SetFocus to the webbrowser control
and send the keys.

So, while not elegant, this solution works great, plus it gives the client
the web account info in their Access form, which is better than using an
external browser.

So, all's well that ends well. :)

Thanks for your help. I kept the notes in case I need them another time.

Neil
 
N

Neil

Thanks!

I don't think it was an issue with the page not having loaded first. I was
waiting until it finished loading before logging in. (I'm logging in with a
button, not automatically when the page is loaded.)

Also, with the Access 2010 web browser control (not the ActiveX one; but the
one that's built into Access 2010), you would reference the object in the
control (sort of like the !Subform.Form syntax). So it would be:

htm = WebBrowser1.Object.Document

In any case, I tried it with Forms(0).Submit, Forms(1).Submit, etc. Forms(0)
was still the search button; but, what do ya know - Forms(1) was the Login
button! So that worked great. Below is my final code, using the embedded
browser. Thanks for all your help!

Dim UserN As Variant
Dim PW As Variant

With Me.wbrAccount.Object
Do While .Busy
Loop

Set UserN = .Document.getElementsByName("username")
If Not UserN Is Nothing Then
UserN(0).Value = Me.Username
End If

Do While .Busy
Loop

Set PW = .Document.getElementsByName("password")
If Not PW Is Nothing Then
PW(0).Value = Me.Password
End If

Do While .Busy
Loop

.Document.Forms(1).submit
End With



You need to do this after the web page has finished loading. In the
vba editor you'd select the WebBrowser control from the top left combo
box (in this case WebBrowser1), then in the combo box to the right
select the DocumentComplete event. It will paste in a stub that looks
like this:

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

End Sub

then:

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As
Variant)
Set htm = WebBrowser1.Document
htm.Forms(0).submit
End Sub

I'm pretty sure this is the right way to do it but it also depends on
if there are multiple forms on the page (and I may be forgetting
something else).

So if there are multiple forms on the page you'd need to change
Forms(0) to Forms(1) etc. You can check this in the browser by looking
at the page source and counting the number of forms.

So every time the document completes it will hit the submit function
for the first form. So you'd probably check which page it's on before
it does that:

Private Sub WebBrowser0_DocumentComplete(ByVal pDisp As Object, URL As
Variant)
Dim htm As HTMLDocument
Set htm = WebBrowser0.Document
If htm.URL = "http://www.First Page" Then
htm.Forms(0).submit
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top