View Full Version : What am i Doing wrong
Sandeepn
08-27-2009, 12:00 PM
Fellas,
 
Any kinda appreciation is less for you guys out there for the forum you have created. I have picked up very useful codes for my job from this site. For the below code i tried everything in the website to get the code to work.
 
Situation :
 
we have this website which the user logs in by providing the username and password. With the below code i am able to pass the login information to the appropriate fields, however I am not to get the code to click the submit button
 
Below is the code
 
 
Public Sub Login()
 
Dim Freakedout As Object
Dim user As String
Dim pass As String
user = "User"
pass = "password"
 
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate "website"
Do Until .ReadyState = 4
DoEvents
Loop
Set Freakedout = .document.all.Item("p_user")
Freakedout.Value = user
Set Freakedout = .document.all.Item("p_passwd")
Freakedout.Value = pass
Set Freakedout = Nothing
Set Freakedout = .document.all.Item("submit")
Do Until .ReadyState = 4
DoEvents
Loop
Freakedout.Click
End With
 
 
 
End Sub
The error i am getting is object variable or with block reference not set at [Freakedout.Click]. I Googled for a solution but with no result.:dunno 
 
please help me to have this code up and running.:help 
 
Below is the script for the input fields on the website.
 
Oracle ID:
<INPUT TYPE="text" NAME="p_user" SIZE="30" MAXLENGTH="30">
<BR>
Password:
<INPUT TYPE="password" NAME="p_passwd" SIZE="30" MAXLENGTH="30">
<BR>
<BR>
<INPUT TYPE="submit" VALUE="Submit">
 
 
 
[For obvious reasons i cant provide you with the website, user and password]
mdmackillop
08-27-2009, 01:06 PM
Here's a version I tried to use on this site.  I'm no expert here, and couldn't find the correct Submit button.  For me, it triggers the Paypal button.
 
 
Public Sub Login()
     
    Dim Freakedout As Object
    Dim user As String
    Dim pass As String
     
    Set IE = CreateObject("InternetExplorer.Application")
    With IE
        
        .Navigate "www.vbaexpress.com (http://www.vbaexpress.com/)"
        Do Until .ReadyState = 4
            DoEvents
        Loop
        .Visible = True
        Set Freakedout = .document.all.Item("vb_login_username")
        Freakedout.Value = Range("A1")
        Set Freakedout = .document.all.Item("vb_login_password")
        Freakedout.Value = Range("A2")
        Set Freakedout = Nothing
        Set Freakedout = .document.all.Item("submit")
        Do Until .ReadyState = 4
            DoEvents
        Loop
        Freakedout.Click
    End With
End Sub
Sandeepn
08-27-2009, 03:00 PM
I tried the same code, it does click the submit button and as you said it does go to paypal. however when i try with my website it still gives the same error :-(
rbrhodes
08-27-2009, 05:26 PM
Is it case senstive?
 
if so "submit" <> "Submit"
 
INPUT TYPE="submit" VALUE="Submit">
Sandeepn
08-28-2009, 08:26 AM
I tried, it still has the same error. I also noticed on microsoft website that it is bug. Anybody has any info abt it, any workaround?
MaximS
08-29-2009, 05:06 AM
can you please submit website address?
Sandeepn
08-30-2009, 02:00 AM
i doubt you can access as it is a internal website, if i try accessing the same on my comp without loggin into my office network it doesn't work. with the below code[which i got in this website] i tried using the  SendKeys "{TAB}" method, it works but for some reason it misses one of the tab and clicks another link.
 
Public Sub LaunchwebsiteSCICOM()
    Const strURL_c As String = "xxxxxxxxxxxxxxxxx (http://az18u514.honeywell.com:33010/pls/hbcprd03/hbc_scicom.authenticate)"
    Const strUsr_c As String = "User"
    Const strPwd_c As String = "Password"
    Const strinv_c As Boolean = "446180"
    Dim objIE As SHDocVw.InternetExplorer
    Dim ieDoc As MSHTML.HTMLDocument
    Dim ieDoc2 As MSHTML.HTMLDocument
    Dim tbxPwdFld As MSHTML.HTMLInputElement
    Dim tbxUsrFld As MSHTML.HTMLInputElement
    Dim InvFld As MSHTML.HTMLInputElement
    Dim btnSubmit As MSHTML.HTMLFormElement
    Set btnSubmit = Nothing
        
    'Create Internet Explorer Object
    Set objIE = New SHDocVw.InternetExplorer
     'Navigate the URL
    objIE.Navigate strURL_c
     'Wait for page to load
    Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
         'Get document object
        Set ieDoc = objIE.document
         'Get username/password fields and submit button.
        Set tbxPwdFld = ieDoc.all.Item("p_passwd")
        Set tbxUsrFld = ieDoc.all.Item("p_user")
            'Fill Fields
        tbxUsrFld.Value = strUsr_c
        tbxPwdFld.Value = strPwd_c
                objIE.Visible = True
                SendKeys "{TAB}", True
                SendKeys "{TAB}", True
                SendKeys "{TAB}", True
                SendKeys "{TAB}", True
                SendKeys "{TAB}", True
                SendKeys "{TAB}", True
                SendKeys "{TAB}", True
                SendKeys "{TAB}", True
                SendKeys "{ENTER}", True
            objIE.Visible = True
            Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
            objIE.Visible = True
            
        End Sub
mdmackillop
08-30-2009, 03:17 AM
can you please submit website address?
I think Maxim means the Microsoft website.
mdmackillop
08-30-2009, 03:48 AM
This checks for the Submit Button value to get the correct object
 
Public Sub Login()
    Dim Freakedout As Object
    Dim user As String
    Dim pass As String
    Dim objElement As Object
    Dim objCollection As Object, o
    Set IE = CreateObject("InternetExplorer.Application")
    With IE
        .Navigate "www.vbaexpress.com (http://www.vbaexpress.com)"
        Do Until .ReadyState = 4
            DoEvents
        Loop
        .Visible = True
        Set Freakedout = .document.all.Item("vb_login_username")
        Freakedout.Value = Range("A1")
        Set Freakedout = .document.all.Item("vb_login_password")
        Freakedout.Value = Range("A2")
        Set objCollection = IE.document.getElementsByTagName("input")
        For Each o In objCollection
            If o.Type = "submit" And _
               o.Value = "Log in" Then
                Set objElement = o
                Exit For
            End If
        Next
   
        Do Until .ReadyState = 4
            DoEvents
        Loop
        objElement.Click
    End With
End Sub
MaximS
08-30-2009, 06:04 AM
maybe that will work for you:
 
 
Private Sub cmdOpen_Click()
 
Dim ie As Object
 
'Establishing connection
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
 
With ie
.navigate "http://www.net.co.uk/" 
Do While .busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
 
    .Document.Forms(0).Item("vb_login_username").Value = "yyyy"
    .Document.Forms(0).Item("vb_login_password").Value = "xxxx"
    .Document.Forms(0).submit.Click
End With
 
End Sub
mdmackillop
08-30-2009, 07:50 AM
Hi Maxim,
I couldn't quite get your code to work on this site, however a couple of minor changes is logging me on, and your layout is much neater.
Regards
Malcolm
 
 
Private Sub cmdOpen_Click()
    Dim ie As Object
    Dim objCollection As Object
    Dim o As Object
    'Establishing connection
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    With ie
        .navigate "http://www.vbaexpress.com/"
        Do While .busy: DoEvents: Loop
        Do While .ReadyState <> 4: DoEvents: Loop
        .document.all.Item("vb_login_username").Value = "md"
        .document.all.Item("vb_login_password").Value = "pass"
        Set objCollection = ie.document.getElementsByTagName("input")
        For Each o In objCollection
            If o.Type = "submit" And o.Value = "Log in" Then
                o.Click
                Exit For
            End If
        Next
    End With
End Sub
Sandeepn
09-16-2009, 10:36 AM
Guys, you are the gods, code works like a punk. One more help, how do i refer a field on the page that loads after login? I tried with my limited knowledge of VB. It throws up an error.
mdmackillop
09-19-2009, 02:05 AM
Can you create an example using this site as the target?
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.