Connecting Tech Pros Worldwide Forums | Help | Site Map

from combo box data - > Open website with username and password

Member
 
Join Date: Aug 2008
Posts: 67
#1: 3 Weeks Ago
I have a form with a combo box called "cmbWebsites".

The combo box row source comes from a select query that returns rows:

0.WebsiteID
1.Website Name
2.Website URL
3.Username
4.Password

Only "Website Name" appears in the combo box. The other columns are set to zero length.

When the user selects a website, the AfterUpdate event will trigger code to build a string that contains the URL, Username and Password of the selected website, and runs it through the FollowHyperlink method.

The only thing I don't know how to do is format the hyperlink so the websites will accept the username and password and automatically get me into the site; like "Roboform".

Even though this isn't a pure MS Access question, I can't imagine that other Access developers haven't done something similar.

Does anyone know how to format a URL with Username and Password, so the FollowHyperlink method automatically gets you into the site?

Thanks,
Adam
best answer - posted by mshmyob
Quote:

Originally Posted by AdamOnAccess View Post

ok, I got pretty far with it but than got hung up at the last moment. Here's what is happening...

Expand|Select|Wrap|Line Numbers
  1. With Me!cmbWebSiteID
  2.    strURL = .Column(1)
  3.    strUNtag = .Column(3)
  4.    strUNtag = Chr(34) & strUNtag & Chr(34)
  5.    strPWtag = .Column(4)
  6.    strPWtag = Chr(34) & strPWtag & Chr(34)
  7.    strMyUN = .Column(6)
  8.    strMyPW = .Column(7)
  9.    strSubmitButton = .Column(5)
  10.    strSubmitButton = Chr(34) & strSubmitButton & Chr(34)
  11. End With
  12.  
  13.  
  14. Dim webBrowser As Object
  15. Set webBrowser = CreateObject("InternetExplorer.Application")
  16.  
  17. With webBrowser
  18.     .Navigate strURL
  19.     .Visible = True
  20.         ' loop until the page has finished loading
  21.         Do While webBrowser.readyState <> 4 Or webBrowser.Busy
  22.            DoEvents
  23.         Loop
  24.        ' username and password are the default element names - if they are different you need to figure them out and change accordingly
  25.        .Document.All.Item(strUNtag).Value = strMyUN
  26.        .Document.All.Item(strPWtag).Value = strMyPW
  27.        .Document.All.Item(strSubmitButton).Click
  28. End With
  29.  
When I run the code, I get this error message...

"Method 'Item' of Object 'NameOfForm' Failed"

The error occurs on this line:
.Document.All.Item(strUNtag).Value = strMyUN

if I remove the variable and run it as a fixed string like this...
.Document.All.Item("Nick").Value = strMyUN

... with "Nick" being the actual name of the Username field on the HTML page, the code works perfectly.

Does anyone know how I can get it to run with the variable?

Thanks,
Adam

Just change your declaration for your elements (strUNtag, etc.) like so:

dim strUNtag

Don't try to add quotes or anything. Do not declare it as string or anything. Or leave out the declarations completeley and it will work.

cheers,

mshmyob's Avatar
Expert
 
Join Date: Jan 2008
Location: witness protection
Posts: 618
#2: 3 Weeks Ago

re: from combo box data - > Open website with username and password


Quote:

Originally Posted by AdamOnAccess View Post

I have a form with a combo box called "cmbWebsites".

The combo box row source comes from a select query that returns rows:

0.WebsiteID
1.Website Name
2.Website URL
3.Username
4.Password

Only "Website Name" appears in the combo box. The other columns are set to zero length.

When the user selects a website, the AfterUpdate event will trigger code to build a string that contains the URL, Username and Password of the selected website, and runs it through the FollowHyperlink method.

The only thing I don't know how to do is format the hyperlink so the websites will accept the username and password and automatically get me into the site; like "Roboform".

Even though this isn't a pure MS Access question, I can't imagine that other Access developers haven't done something similar.

Does anyone know how to format a URL with Username and Password, so the FollowHyperlink method automatically gets you into the site?

Thanks,
Adam

I guess that would depend on the format that the Web site requires. For instance I have a map button for my addresses and I open a google map to display my contacts driving directions. The string I send to google maps is based on their format.

I also retrieve stock and index indormation from numerous sites but they require me to pass a string in a certain syntax.

All you need to figure out is what syntax the site expects and do something like so:

Expand|Select|Wrap|Line Numbers
  1. Dim strURL As String
  2. strURL = "http://maps.google.com/maps?q=" & txtAddrStreet & ",+" & txtAddrCity & ",+" & txtAddrProv & "+" & txtAddrPostal & "+" & txtAddrCountry
  3. Application.FollowHyperlink strURL
  4.  
cheers,
Member
 
Join Date: Aug 2008
Posts: 67
#3: 3 Weeks Ago

re: from combo box data - > Open website with username and password


mshmyob,

Thanks for the reply. I know I need the format, but I was thinking that perhaps there was some kind of "standard" for usernames and passwords. Are you familiar with the program, "Roboform". It maintains usernames and passwords for any site you choose. Just click a button, and it stores the URL, username and password. When you want to return to the site, you just click it and in you go. How does Roboform manage to send usernames and passwords to ANY website without first knowing the format?

There must be some standard way to do this. Any one know how?

-Adam
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#4: 3 Weeks Ago

re: from combo box data - > Open website with username and password


I'm not familiar with RoboForm Adam, but from your own description, it seems that it holds it per site. I expect it determines the format from usage somehow (and stores it with your username and password in its database). I certainly think (no great expert at this to be sure so don't take as gospel) that Mshmyob is on the right lines with this though.
mshmyob's Avatar
Expert
 
Join Date: Jan 2008
Location: witness protection
Posts: 618
#5: 3 Weeks Ago

re: from combo box data - > Open website with username and password


I will try and look into it this weekend. I have done a little research and thrown something together but I am having a few errors. Give me a couple of days and I will see what I can come up with if anything.

cheers,
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,214
#6: 3 Weeks Ago

re: from combo box data - > Open website with username and password


I'm not sure of the specific syntax, but you may be able to use the ExtraInfo Parameter of the FollowHyperlink Method to accomplish this.
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,214
#7: 3 Weeks Ago

re: from combo box data - > Open website with username and password


Quote:

Originally Posted by AdamOnAccess View Post

I have a form with a combo box called "cmbWebsites".

The combo box row source comes from a select query that returns rows:

0.WebsiteID
1.Website Name
2.Website URL
3.Username
4.Password

Only "Website Name" appears in the combo box. The other columns are set to zero length.

When the user selects a website, the AfterUpdate event will trigger code to build a string that contains the URL, Username and Password of the selected website, and runs it through the FollowHyperlink method.

The only thing I don't know how to do is format the hyperlink so the websites will accept the username and password and automatically get me into the site; like "Roboform".

Even though this isn't a pure MS Access question, I can't imagine that other Access developers haven't done something similar.

Does anyone know how to format a URL with Username and Password, so the FollowHyperlink method automatically gets you into the site?

Thanks,
Adam

Just retrieve the Username and Password Control Names as well as the Form Name from the Web Site (View Source), and you should be OK:
Expand|Select|Wrap|Line Numbers
  1. Dim objIE As Object
  2. Set objIE = CreateObject("InternetExplorer.Application")
  3.  
  4. With objIE
  5.   .Visible = True
  6.   .Navigate "<Your Web Site>"
  7.  
  8.    Do While .ReadyState <> 4
  9.      DoEvents
  10.    Loop
  11.  
  12.    With .Document.Forms(0)
  13.      .UserName.Value = "your login"         'Retrieve Control Name from Web Page
  14.      .Password.Value = "your password"      'Retrieve Control Name from Web Page
  15.        .Document.loginForm.submit           'Retrieve Form Name from Web Page
  16.    End With
  17. End With
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,214
#8: 3 Weeks Ago

re: from combo box data - > Open website with username and password


I've developed some code that is slightly convoluted, does not require advance knowledge of any Control/Form Names, and actually worked very well during many trials. It involves the use of the FollowHyperlink Method, SendKeys, and the Sleep() API Function. You can judge for yourself:
  1. Declare the API Function:
    Expand|Select|Wrap|Line Numbers
    1. Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  2. Execute the following code block:
    Expand|Select|Wrap|Line Numbers
    1. Const conWEB_ADDRESS As String = "<YaDa, YaDa, YaDa>"
    2. Const conUSERNAME As String = "<more YaDa, YaDa>"
    3. Const conPASSWORD As String = "<still more YaDa, YaDa>"
    4.  
    5. Application.FollowHyperlink Address:=conWEB_ADDRESS
    6.  
    7. Sleep (3000)    'Delay 3 seconds
    8. SendKeys conUSERNAME, True      'Plug in User Name
    9.  
    10. Sleep (1000)    'Delay 1 second
    11. SendKeys "{TAB}", True          'Send the TAB Keystroke
    12.  
    13. Sleep (1000)    'Delay 1 second
    14. SendKeys conPASSWORD, True      'Plug in Password
    15.  
    16. Sleep (1000)    'Delay 1 second
    17. SendKeys "{TAB}", True          'Send the TAB Keystroke
    18.  
    19. Sleep (1000)    'Delay 1 second
    20. SendKeys "{ENTER}"              'Send the ENTER Keystroke 
NOTE: You can experiment with the Delays for better performance.
mshmyob's Avatar
Expert
 
Join Date: Jan 2008
Location: witness protection
Posts: 618
#9: 3 Weeks Ago

re: from combo box data - > Open website with username and password


Here is a simple way of submitting your username and password to various sites.

Expand|Select|Wrap|Line Numbers
  1. ' you need a reference to the Microsoft HTML Object Library
  2. Dim webBrowser As Object
  3. Set webBrowser = CreateObject("InternetExplorer.Application")
  4.  
  5. With webBrowser
  6.     .Navigate "put your login URL here"
  7.     .Visible = True
  8.         ' loop until the page has finished loading
  9.         Do While webBrowser.readyState <> 4
  10.            DoEvents
  11.         Loop
  12.        ' username and password are the default element names - if they are different you need to figure them out and change accordingly
  13.        .Document.all.Item("USERNAME").Value = "your username"
  14.        .Document.all.Item("PASSWORD").Value = "your password"
  15. End With
  16.  
cheers,
Member
 
Join Date: Aug 2008
Posts: 67
#10: 3 Weeks Ago

re: from combo box data - > Open website with username and password


Mshmyob, ADezii, NeoPa,

Thanks all! Lot's of great stuff to work with here. My biggest problem now is deciding which solution is best? It seems the real tricky part here is capturing the object names for username and password in the html form. I suppose I could create fields in the database to store that info, use view page to capture the actual names, and then slug them in when I run the code.

Not the kind of thing I'd expect most users to pull off. I could set "Username" and "Password" as default field names and that will probably cover most of it.
Thanks again!

-Adam
Member
 
Join Date: Aug 2008
Posts: 67
#11: 2 Weeks Ago

re: from combo box data - > Open website with username and password


ok, I got pretty far with it but than got hung up at the last moment. Here's what is happening...

Expand|Select|Wrap|Line Numbers
  1. With Me!cmbWebSiteID
  2.    strURL = .Column(1)
  3.    strUNtag = .Column(3)
  4.    strUNtag = Chr(34) & strUNtag & Chr(34)
  5.    strPWtag = .Column(4)
  6.    strPWtag = Chr(34) & strPWtag & Chr(34)
  7.    strMyUN = .Column(6)
  8.    strMyPW = .Column(7)
  9.    strSubmitButton = .Column(5)
  10.    strSubmitButton = Chr(34) & strSubmitButton & Chr(34)
  11. End With
  12.  
  13.  
  14. Dim webBrowser As Object
  15. Set webBrowser = CreateObject("InternetExplorer.Application")
  16.  
  17. With webBrowser
  18.     .Navigate strURL
  19.     .Visible = True
  20.         ' loop until the page has finished loading
  21.         Do While webBrowser.readyState <> 4 Or webBrowser.Busy
  22.            DoEvents
  23.         Loop
  24.        ' username and password are the default element names - if they are different you need to figure them out and change accordingly
  25.        .Document.All.Item(strUNtag).Value = strMyUN
  26.        .Document.All.Item(strPWtag).Value = strMyPW
  27.        .Document.All.Item(strSubmitButton).Click
  28. End With
  29.  
When I run the code, I get this error message...

"Method 'Item' of Object 'NameOfForm' Failed"

The error occurs on this line:
.Document.All.Item(strUNtag).Value = strMyUN

if I remove the variable and run it as a fixed string like this...
.Document.All.Item("Nick").Value = strMyUN

... with "Nick" being the actual name of the Username field on the HTML page, the code works perfectly.

Does anyone know how I can get it to run with the variable?

Thanks,
Adam
mshmyob's Avatar
Expert
 
Join Date: Jan 2008
Location: witness protection
Posts: 618
#12: 2 Weeks Ago

re: from combo box data - > Open website with username and password


Quote:

Originally Posted by AdamOnAccess View Post

ok, I got pretty far with it but than got hung up at the last moment. Here's what is happening...

Expand|Select|Wrap|Line Numbers
  1. With Me!cmbWebSiteID
  2.    strURL = .Column(1)
  3.    strUNtag = .Column(3)
  4.    strUNtag = Chr(34) & strUNtag & Chr(34)
  5.    strPWtag = .Column(4)
  6.    strPWtag = Chr(34) & strPWtag & Chr(34)
  7.    strMyUN = .Column(6)
  8.    strMyPW = .Column(7)
  9.    strSubmitButton = .Column(5)
  10.    strSubmitButton = Chr(34) & strSubmitButton & Chr(34)
  11. End With
  12.  
  13.  
  14. Dim webBrowser As Object
  15. Set webBrowser = CreateObject("InternetExplorer.Application")
  16.  
  17. With webBrowser
  18.     .Navigate strURL
  19.     .Visible = True
  20.         ' loop until the page has finished loading
  21.         Do While webBrowser.readyState <> 4 Or webBrowser.Busy
  22.            DoEvents
  23.         Loop
  24.        ' username and password are the default element names - if they are different you need to figure them out and change accordingly
  25.        .Document.All.Item(strUNtag).Value = strMyUN
  26.        .Document.All.Item(strPWtag).Value = strMyPW
  27.        .Document.All.Item(strSubmitButton).Click
  28. End With
  29.  
When I run the code, I get this error message...

"Method 'Item' of Object 'NameOfForm' Failed"

The error occurs on this line:
.Document.All.Item(strUNtag).Value = strMyUN

if I remove the variable and run it as a fixed string like this...
.Document.All.Item("Nick").Value = strMyUN

... with "Nick" being the actual name of the Username field on the HTML page, the code works perfectly.

Does anyone know how I can get it to run with the variable?

Thanks,
Adam

Just change your declaration for your elements (strUNtag, etc.) like so:

dim strUNtag

Don't try to add quotes or anything. Do not declare it as string or anything. Or leave out the declarations completeley and it will work.

cheers,
Member
 
Join Date: Aug 2008
Posts: 67
#13: 2 Weeks Ago

re: from combo box data - > Open website with username and password


Works great! Thanks MshMyob!
Reply


Similar Microsoft Access / VBA bytes