Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ie automation problem

Status
Not open for further replies.

robcarr

Programmer
May 15, 2002
633
GB
hi,

i am using the below code to enter data into a web page

Code:
Public Sub CreateICEBRecord()
    Dim rdate As Date
    Dim rdesc As String
    Dim rbenefit As String
    Dim URL As String
    Dim IE As Object
    Dim f As Integer, e As Integer
    
    URL = "[URL unfurl="true"]https://www.iceb.com/magicsiteltest/bin/Main.php?menu=request_fiche&_action=0"[/URL]
    
    Set IE = CreateObject("InternetExplorer.Application")
        
    rtitle = Range("b2").Value
    ramount = Range("b3").Value
    rcharge = Range("b4").Value
    If rcharge = "Yes" Then
    rcharge = 1
    Else
    rcharge = 2
    End If
    rlocation = Range("b6").Value
    rdesc = Range("b7").Value
    rbenefit = Range("b8").Value
    With IE
        .Visible = True
        .Navigate URL
        Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
    End With
    With IE
   .Document.Forms("AddReq").elements("_reqapp").Value = "25"
    Call IE.Document.parentWindow.execScript("document.AddReq.submit();this.disabled=true;", "javascript")
     Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
    .Document.Forms("savereq").elements("_reqtitle").Value = rtitle
    .Document.Forms("savereq").elements("DF_37").selectedIndex = 1
    .Document.Forms("savereq").elements("DF_37").onchange
    .Document.Forms("savereq").elements("df_4").selectedIndex = "5"
    .Document.Forms("savereq").elements("DF_5").Value = Round(ramount, 0)
    .Document.Forms("savereq").elements("DF_3").selectedIndex = "1"
    .Document.Forms("savereq").elements("DF_3").onchange
    .Document.Forms("savereq").elements("df_48").Value = rcharge
    .Document.Forms("savereq").elements("df_11").Value = Date
    .Document.Forms("savereq").elements("DF_7").selectedIndex = 1
    .Document.Forms("savereq").elements("DF_7").onchange
    .Document.Forms("savereq").elements("df_49").selectedIndex = 5
    .Document.Forms("savereq").elements("DF_24").selectedIndex = 54
    .Document.Forms("savereq").elements("DF_24").onchange
    .Document.Forms("savereq").elements("df_21").Value = 18
    .Document.Forms("savereq").elements("newdesc").Value = rdesc
    .Document.Forms("savereq").elements("reqbenefits").Value = rbenefit
    End With
    
    
    Set IE = Nothing
    
End Sub
if i step through the code it works fine

if i run it it fails on

Code:
.Document.Forms("savereq").elements("DF_7").onchange

any ideas what can be causing it.

Once I get this it should save me about 5 mins per form, 15 forms per week so i would like to try and nail it if poss.

thanks

Hope this is of use, Rob.[yoda]
 
I'd try to call DoEvents after each onchange call.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I had the

Do While .Busy Or .ReadyState <> 4: DoEvents: Loop


after but it still didnt make any difference, it just seems that the vba code goes to quick.

Rob.

Hope this is of use, Rob.[yoda]
 
i added an application wait of 1 second per onchange and it sorted the problem

Hope this is of use, Rob.[yoda]
 
1 second is fine 10 is too long the drop down refresh really quickly 1 had to keep checking the coding on 10 secs as i thought it had stopped all the time

Hope this is of use, Rob.[yoda]
 
I have this working quite well now, I have noticed however the webmaster occasionally change the locations of the combo box values.

Code:
 .Document.Forms("savereq").elements("DF_24").selectedIndex = 54

sometimes the value in 54 could be in 48 or 70, unfortunately I have no way to get them to set them as defaults, is there a way to get the selectedindex entered by using the value and not the index, as I know what I want to put in/select (this value never changes) but i don't know how to enter it into the box without selecting the index number, every time I try the box goes blank and wont show the value I want it to show.

I was thinking if I could loop the combobox until the indexed value matches my value? but alas i don't know how to do this.




Hope this is of use, Rob.[yoda]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top