Problem with trying to open a URL and login automatically

Harris@Z

Registered User.
Local time
Today, 22:34
Joined
Oct 28, 2019
Messages
97
Hi,
I am struggling to find an example of code that will open an URL and login to the site automatically.
I am trying to login to this site: id.caspio_com

One example shows error at
Code:
oLogin.value = Username with the error "Object variable or With block variable not set" - run-time error '91'

Can anyone assist please?
Code:
Public Function OpenURL2(TheURL as string, TheUserName As String, Passwd As String)
    
Const Url$ = TheURL 

 
    
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")

    With ie

        .Navigate Url
        ieBusy ie
        .Visible = True

        Dim oLogin As Object, oPassword As Object
        Set oLogin = .Document.getElementsByName("ecp_param_userId")(0)
        Set oPassword = .Document.getElementsByName("ecp_param_password")(0)

        oLogin.Value = TheUserName
        oPassword.Value = Passwd
        .Document.Forms(0).submit

    End With

End Function

Tried to post the full code example but will not accept!

Any working sample code will be greatly appreciated please!
 
Have you walked through the code to see if everything is set?

Edit: When I try your code after a few amendments and use the correct url, oLogin is not set?

Code:
Public Sub OpenURL2(TheURL As String, TheUserName As String, Passwd As String)
  
'Const Url$ = TheURL


    Dim oLogin As Object, oPassword As Object
    Dim ie As SHDocVw.InternetExplorer
    Dim varBusy As Variant
    Set ie = CreateObject("InternetExplorer.Application")

    With ie

        .Navigate TheURL
        varBusy = .Busy
        .Visible = True

      
        Set oLogin = .Document.getElementsByName("EmailField")(0)
        Set oPassword = .Document.getElementsByName("ecp_param_password")(0)

        oLogin.value = TheUserName
        oPassword.value = Passwd
        .Document.Forms(0).submit

    End With

End Sub

However, I am not up on web access with VBA and the fields appear to be called EmailField and PasswordField ?
Perhaps look at Similar Threads at the bottom of this page.
 
Last edited:
You can sort out the button click yourself.

Code:
Public Sub OpenURL2(TheURL As String, TheUserName As String, Passwd As String)
    
'Const Url$ = TheURL

 
    Dim oLogin As Object, oPassword As Object
    Dim ie As SHDocVw.InternetExplorer
    Dim varBusy As Variant
    Set ie = CreateObject("InternetExplorer.Application")

    With ie

        .Navigate TheURL
        varBusy = .Busy
        .Visible = True

        
        .Document.getElementByID("EmailField").value = TheUserName
        .Document.getElementByID("PasswordField").value = Passwd

        '.Document.Forms(0).submit this does not work?

    End With

End Sub
 
This appears to work if you have the correct credentials?
Code:
        .Document.getElementByID("EmailField").value = TheUserName
        .Document.getElementByID("PasswordField").value = Passwd
        .Document.getElementByID("LoginButton").Click
 
Thanks very much for your input.
I am not an advanced programmer so not sure how to resolve some problems.
When running your code, I get the following error for

Dim ie As SHDocVw.InternetExplorer

Compile error: User-defined type not defined.

Do I need to include a reference?

Regards,
Harris
 
Probably, but not sure which one, as it did not complain for me.
This is what I have in my Access.

Try adding Internet Controls
1716556156315.png
 

Attachments

  • 1716556104310.png
    1716556104310.png
    39.6 KB · Views: 50
I did get it to work, thank you, by replacing the following

Dim IE As SHDocVw.InternetExplorer
Set IE = CreateObject("InternetExplorer.Application")

With

Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")

Thanks so much!

Only problem remaining is the login button
.Document.getElementByID("LoginButton").Click does not work, and as you pointed out, Document.Forms(0).submit also not.

Any other option to try?
 
Thank you! Then how do I resolve the error with Dim IE As SHDocVw.InternetExplorer as mentioned earlier?
 
I solved the problem of Dim IE As SHDocVw.InternetExplorer - my Microsoft Internet Controls was not referenced!

So remaining problem is simply this:
.Document.getElementByID("LoginButton").Click

Any recommendations?
 
It works for me? just that I do not get anywhere as the login details are incorrect.
I tried it on a site that I use regularly, but they do not accept IE.

Edit: I cannot find a website that will accept IE by the looks of it? :(
 
Last edited:

Users who are viewing this thread

Back
Top Bottom