0

Good Afternoon All,

I have created some code that automatically logs me into my works website, however when trying to get the VBA to enter value into one of the search boxes I always recieve error 438: Object doesn't support this propery or method.

This is my code below please can you help:

Option Explicit

Const MyUserName As String = "username"
Const MyPassword As String = "password"

Const READYSTATE_COMPLETE As Integer = 4

Dim objIE As Object


Sub LoginScript()

Dim Message, Title, Default
Dim MyValue As String
Dim currenttime As Date

Set objIE = CreateObject("InternetExplorer.Application")

    If MsgBox("Do you want to search for a member?", vbYesNo, "Login") = 
vbNo Then
With objIE
.Visible = True
.Silent = True
.Navigate ("https://XXXXXXXXX.com/")
Do Until .ReadyState = READYSTATE_COMPLETE
  DoEvents
Loop
.Document.all.txtuserid.Value = MyUserName
.Document.all.txtpassword.Value = MyPassword
.Document.all.save_button.Click
Do Until .ReadyState = READYSTATE_COMPLETE
  DoEvents
Loop
End With
    Else

    Message = "Please enter clients CTC number"    ' Set prompt.
    Title = "Member Search"    ' Set title.
    ' Display message, title, and default value.
     MyValue = InputBox(Message, Title)

With objIE
    .Visible = True
    .Silent = True
    .Navigate ("https://XXXXXXXXX.com/")
    Do Until .ReadyState = READYSTATE_COMPLETE
    DoEvents
    Loop
    .Document.all.txtuserid.Value = MyUserName
    .Document.all.txtpassword.Value = MyPassword
    .Document.all.save_button.Click
    Do Until .ReadyState = READYSTATE_COMPLETE
    DoEvents
    Loop
    currenttime = Now
    Do Until currenttime + TimeValue("00:00:10") <= Now
    Loop
    Do Until .ReadyState = READYSTATE_COMPLETE
    DoEvents
    Loop
    .Document.getElementsById("txtClientRef").Value = MyValue <------ Errors Here
End With
End If
End Sub
4
  • Why are you using a different method to fill in the search field than your login credentials? Which, by the way, is a very bad idea. Commented May 15, 2018 at 16:22
  • I tried the same method and this didnt work either. I am the only one with access the the file that contains the code and i have aldo password protected the file Commented May 15, 2018 at 16:58
  • exceldevelopmentplatform.blogspot.com/2018/02/… Helps to set the focus on the control you are manipulating. Commented May 15, 2018 at 19:13
  • I am still receiving error 424 Commented May 16, 2018 at 12:31

1 Answer 1

2

Id should be unique, and the syntax is getElementById, so try:

 .Document.getElementById("txtClientRef").Value

It is also a good idea to do .Document.getElementById("txtClientRef").Focus first.

If this then yields runtime error 424 it may be either that the object doesn't exist, as specified, or is not available at the time you attempt the assignment. For the latter to you can attempt to loop until not nothing with a specified timeout.

Sign up to request clarification or add additional context in comments.

8 Comments

Beat me to it. Posting the: .Document.getElementsById("txtClientRef").Value
This has now caused the error to change. I am now getting error 424. Object Required
Well that suggests it either doesn't exist or is not available at the time you attempt the assignment.
Is there a URL to share? And did you right click inspect on the element in the webpage?
unfortunately I can not share the URL as it is used by my work for all of our clients. I have inspected the page and the box I am trying to fill is under a Span class with the name "form_element varchar" then the ID of the box is "txtClientRef"
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.