samedi 3 juin 2017

Access & VBA: web page complex control

from my application in Access & VBA I have to open a login web page in a web application (developed from other company). After, I have to fill the form and login. After correct login, the app closes the browser automatically and open an other web page with the first user page.

Now, the problem is that the second web page works correctly only if I put a certain msg box; in other case, I see a "not set variable" in the indicated block.

Why? I would that, all works correctly without any msg box. Thank all!

Private Sub managerDocsPa()

Dim ie As Object
Dim IeDoc As HTMLDocument
Set ie = CreateObject("InternetExplorer.application")
ie.Navigate ("http://ift.tt/2rChV5x")
ie.Visible = True
Do While ie.Busy: DoEvents: Loop
Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
Set IeDoc = ie.Document

With IeDoc
       'MsgBox .title
      .getElementById("userid").Value = "myuser"
      .getElementById("password").Value = "mypass"
      .getElementById("btn_login").Click
End With

Do While ie.Busy: DoEvents: Loop
Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

Dim SWs As SHDocVw.ShellWindows, vIE As SHDocVw.InternetExplorer
Dim winShell As Shell
Dim dt As Date
dt = DateAdd("s", 10, DateTime.Now)
Dim ieA As InternetExplorer
Dim IeDocA As HTMLDocument
Do While dt > DateTime.Now

   Set winShell = New Shell

   For Each ieA In winShell.Windows
       If ieA.LocationURL = sURL Then

       ieA.Visible = True
       ieA.Silent = True

       Do While ieA.Busy: DoEvents: Loop
       Do Until ieA.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
       Set IeDocA = ieA.Document
       
       //Why it works only with this message?
       MsgBox "abc"


       //Without the message, at this point I see the error
       With IeDocA
           .getElementsByName("sampleButton")(0).Click
       End With

       Set winShell = Nothing
       Exit Do

       End If

   Next ieA
   Set winShell = Nothing
   DoEvents

Loop

End Sub



Aucun commentaire:

Enregistrer un commentaire