Link to home
Start Free TrialLog in
Avatar of bill201
bill201

asked on

why my code login on a web site with access vba don't work on microsoft access 2016

hi

this is my code:
Private Sub Command0_Click()
   With CreateObject("InternetExplorer.Application")
     .Navigate "http://www.login.com/Ext_Login.aspx"
     Do Until .ReadyState = 4
       DoEvents
     Loop
     DoEvents
     With .Document
        Document.items("frmLogin$UserName") = "username"
        .items("frmLogin$Password") = "12345"
        .items("frmLogin$LoginButton").submit
     End With
  End With
End Sub

Open in new window


but when i try to use this code i get an error message run time error 424 object required and i when i click on debug i see a error message on this line
 Document.items("frmLogin$UserName") = "username"

Open in new window

.

on the references microsoft internet controls is selected.

thanks a lot
Avatar of Michael
Michael
Flag of Belgium image

Does this help?
Private Sub Command0_Click()
   Set objIE = CreateObject("InternetExplorer.Application")
   With objIE
     .Navigate "http://www.login.com/Ext_Login.aspx"
     Do Until .ReadyState = 4
       DoEvents
     Loop
     DoEvents
     With .Document
        .items("frmLogin$UserName") = "username"
        .items("frmLogin$Password") = "12345"
        .items("frmLogin$LoginButton").submit
     End With
  End With
End Sub

Open in new window

Avatar of bill201
bill201

ASKER

thanks a lot but the code still don't works. this is how the code is written now
    Set Document = CreateObject("internetexplorer.application")
    With Document
    .Navigate "http://www.login.com/Ext_Login.aspx"
    Do Until .ReadyState = 4
       DoEvents
     Loop
     DoEvents
        .items("frmLogin$UserName") = "username"
        .items("frmLogin$Password") = "12345"
        .items("frmLogin$LoginButton").submit
  End With

Open in new window


and this is the error message that i get
run time error 438
object dosn't support this property or method.
Avatar of bill201

ASKER

thanks a lot but also the new code don't work and i got the same error message, is there a possibility to make visible the vba internet explorer browser, then i will maybe be able to see what is going on?
Avatar of Norie
Try this.
Private Sub Command0_Click()
Dim objIE As Object
Dim doc As Object 

   Set objIE = CreateObject("InternetExplorer.Application")

   With objIE
     .Navigate "http://www.login.com/Ext_Login.aspx"
     Do Until .ReadyState = 4
       DoEvents
     Loop
     .Visible = True

     Set doc = .document
   End With
   
     With doc
        .items("frmLogin$UserName") = "username"
        .items("frmLogin$Password") = "12345"
        .items("frmLogin$LoginButton").submit
     End With

End Sub

Open in new window

Are you absolutely sure the web document is the same (i.e. that "frmLogin$UserName" exists)?
Avatar of bill201

ASKER

thanks a lot now it's open the page but still it's dosn't fill the name and password, i will give you the html source code and please check me whats wrong with my field name.

this is the code
                <table cellspacing="0" cellpadding="4" id="frmLogin" style="background-color:#F7F6F3;border-color:#E6E2D8;border-width:1px;border-style:Solid;border-collapse:collapse;right: 230px; position: absolute; top: 450px; width: 320px; height:170px">
	<tr>
		<td><table cellpadding="0" style="color:#333333;font-family:Arial;font-size:Medium;height:120px;">
			<tr>
				<td align="center" colspan="2" style="color:White;background-color:#5D7B9D;font-size:14pt;font-weight:bold;">הכנסת פרטים מזהים</td>
			</tr><tr>
				<td align="right" style="font-size:Medium;"><label for="frmLogin_UserName">שם משתמש</label></td><td><input name="frmLogin$UserName" type="text" id="frmLogin_UserName" style="font-size:Medium;height:25px;width:200px;" /><span id="frmLogin_UserNameRequired" title="User Name is required." style="visibility:hidden;">*</span></td>
			</tr><tr>
				<td align="right" style="font-size:Medium;"><label for="frmLogin_Password">סיסמא</label></td><td><input name="frmLogin$Password" type="password" id="frmLogin_Password" style="font-size:Medium;height:25px;width:200px;" /><span id="frmLogin_PasswordRequired" title="Password is required." style="visibility:hidden;">*</span></td>
			</tr><tr>
				<td align="right" colspan="2"><input type="submit" name="frmLogin$LoginButton" value="אישור" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;frmLogin$LoginButton&quot;, &quot;&quot;, true, &quot;frmLogin&quot;, &quot;&quot;, false, false))" id="frmLogin_LoginButton" style="color:#284775;background-color:#FFFBFF;border-color:#CCCCCC;border-width:1px;border-style:Solid;font-family:Arial;font-size:Medium;height:25px;" /></td>
			</tr>
		</table></td>
	</tr>
</table>
    </strong>    


    <table   style="right: 230px; position: absolute; top: 630px; font-size: small; font-weight: 700;">
          <tr>
      <td>
          <a href="#" onclick="showItems('lblenterusername','txtpassRecover1','btnrecPass',this);">
      <span id="label1" style="font-family:Arial;font-size: x-small">שכחת את סיסמתך?</span></a>
    </td>  </tr>
       
        <tr><td>
     <span id="lblenterusername" style="font-family:Arial;font-size: x-small;display: none;">אנא הכנס שם משתמש על מנת לקבל את סיסמתך:</span>
            </td>
            </tr>
         <tr><td>
    <input name="txtpassRecover1" type="text" id="txtpassRecover1" style="width:120px;display: none;" />   </td>
            </tr>
          <tr><td>
        <input type="submit" name="btnrecPass" value="שלח" id="btnrecPass" style="height:25px;display: none;" />  </td>
            </tr>
           
               </table>

                <!-- sub Box ------->
                
                
<script type="text/javascript">
//<![CDATA[
var Page_Validators =  new Array(document.getElementById("frmLogin_UserNameRequired"), document.getElementById("frmLogin_PasswordRequired"));
//]]>
</script>

<script type="text/javascript">
//<![CDATA[
var frmLogin_UserNameRequired = document.all ? document.all["frmLogin_UserNameRequired"] : document.getElementById("frmLogin_UserNameRequired");
frmLogin_UserNameRequired.controltovalidate = "frmLogin_UserName";
frmLogin_UserNameRequired.errormessage = "User Name is required.";
frmLogin_UserNameRequired.validationGroup = "frmLogin";
frmLogin_UserNameRequired.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
frmLogin_UserNameRequired.initialvalue = "";
var frmLogin_PasswordRequired = document.all ? document.all["frmLogin_PasswordRequired"] : document.getElementById("frmLogin_PasswordRequired");
frmLogin_PasswordRequired.controltovalidate = "frmLogin_Password";
frmLogin_PasswordRequired.errormessage = "Password is required.";
frmLogin_PasswordRequired.validationGroup = "frmLogin";
frmLogin_PasswordRequired.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
frmLogin_PasswordRequired.initialvalue = "";
//]]>
</script>

Open in new window


this is the web page http://www.enativ.com/Ext_Login.aspx
(the labels are in hebrew so i hope you will understand the code).

thanks a lot
Avatar of bill201

ASKER

what i understand it's a form on the web page http://www.enativ.com/Ext_Login.aspx, the form name is form1 and the login username field name on the form is frmLogin_UserName, so how i has to write the address on vba ?
This appears to work.
Private Sub Command0_Click()
Dim objIE As Object
Dim doc As Object
Dim frm As Object

    Set objIE = CreateObject("InternetExplorer.Application")

    With objIE
        .Navigate "http://www.enativ.com/Ext_Login.aspx"
        Do Until .ReadyState = 4
            DoEvents
        Loop
        .Visible = True

        Set doc = .document
    End With

    Set frm = doc.forms(0)

    frm("frmLogin_UserName").Value = "username"
    frm("frmLogin_Password").Value = "12345"
    frm.submit

End Sub

Open in new window

Avatar of bill201

ASKER

thanks a lot the username has been filled out, but not the password, why is that? (maybe it's possible to solving the problem with  the  tab key, to send a tab button after filling out the username field, how can i send a tab key?)
When I run the code there's definitely something going in the password box - I can actually 'see' it happening when I step through.

Of course when the form is submitted there's a 'Login Failed' message but that's expected since the code doesn't use a valid username/password combination.
Avatar of bill201

ASKER

Thanks for your excellent answer but I need a solution how to fill the password. I need it for my employees that are not familior with internet, so I prefer to make thanks easy for them, so they will not have to press any password, every think will be make auto by programming.
As I said, when I run the code I posted the password is filled in.

Did you change what I posted in any way?
Avatar of bill201

ASKER

no, i don't change nothing it's just don't fill the form, what browser do you use?
Avatar of bill201

ASKER

now i test it in another way to put the password and then the name but after it's fill the name it's been deleted the password for some reason
The code uses whichever version of Internet Explorer you have installed.

It doesn't work with any other browser.

Are you entering a valid username and password in the code?
Avatar of bill201

ASKER

yes its a valid login, and when i fill the details manually, i log in
Avatar of bill201

ASKER

i'm able to login manually with the same version that the vba don't work, it's internet explorer 11, how can i try to login with another browser like chrome for example ?
If you comment out this line, run the code and goto Internet Explorer has something been entered in the password field?
   frm.submit

Open in new window

Avatar of bill201

ASKER

yes the password is filled out and i'm able to login.
So the code is filling in the password and the problem appears to be when actually submitting the form?

When you run the code without that line commented out do you get any messages on the webpage?

For example, incorrect username/password?
Avatar of bill201

ASKER

No I don't get  any message before I click On the login button.
I mean when you run the code through, including this line.
frm.submit

Open in new window

When I do that I get a message asking if I've forgotten the password.

Also, when that happens the password field is cleared so it appears as though a password was never entered.
Avatar of bill201

ASKER

because i don't  attached here the correct login information  (i can send it to you privately the login details
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bill201

ASKER

now its working thanks a million
Avatar of bill201

ASKER

full and exact answer, thank you and thanks for every one that tried to help