IE Scripting problem from Access VBA

Ancalima

Registered User.
Local time
Yesterday, 22:42
Joined
Oct 8, 2008
Messages
11
Hi everyone,

I am haing a little trouble with an access app i'm creating which is meant to interact with a website in internet explorer. Here is the code:

Code:
    Dim IEX  As InternetExplorer
    
    Set IEX = CreateObject("InternetExplorer.Application")
    IEX.Visible = True
    
    IEX.Navigate (website name hidden for security reasons)
    
    Do Until IEX.Busy = False
        DoEvents
    Loop
 
    Sleep 1000
    DoEvents
    SendKeys "y"
    DoEvents
    Sleep 250
    DoEvents
    SendKeys "{ENTER}"
    DoEvents
    Sleep 1000
 
    Do Until IEX.Busy = False
        DoEvents
    Loop
    
    IEX.Document.Forms("Form1").Item("Username").Value = Username
    IEX.Document.Forms("Form1").Item("password").Value = Password
    IEX.Document.Forms("Form1").Item("domain").Value = Domain
    IEX.Document.all.Item("submitButton").Click

The site that opens is a login page. The problem I am having is that for this site, whenever it opens, 1 or two message boxes pop up. This is the reason for the sendkeys portion of the code. I really want to avoid using sendkeys on this as the window doesnt always open on top of the other applications open on my pc. So my question is:

Is there any way to access the message boxes that pop up in IE and simulate clicking the appropriate buttons without using sendkeys or having user interaction?

Any help on this topic would be greatly appreciated as I am totally stumped. Thanks.
 
Hi All,

I thought I might share my solution to any who might be having a similar problem. It still uses sendkeys but to a very limited extent. First it checks to see that the popup window is open and then it brings the internet explorer window to the top(which, in turn, brings the popup to the top) and then it sends the key, and loops on this procedure for each popup window until it determines that it was successful.

Code:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpszClassName As String, ByVal lpszWindow As String) As Long
Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Boolean
 
Public Sub Login(Username As String, Password As String, Domain As String)
 
    Dim IEX  As InternetExplorer
 
    Set IEX = CreateObject("InternetExplorer.Application")
    IEX.Visible = True
 
    IEX.Navigate (URL hidden for security purposes)
 
    Do Until IEX.ReadyState = READYSTATE_COMPLETE
        DoEvents
        If IEX.ReadyState = READYSTATE_INTERACTIVE Then
            If FindWindow(vbullstring, "Security Alert") <> 0 Then
                BringWindowToTop (IEX.hwnd)
                SendKeys "y"
            ElseIf FindWindow(vbNullString, "Microsoft Internet Explorer") <> 0 Then
                BringWindowToTop (IEX.hwnd)
                SendKeys "{ENTER}"
            End If
        End If
        DoEvents
    Loop
 
    IEX.Document.Forms("frmUserID").Item("username").Value = Username
    IEX.Document.Forms("frmUserID").Item("password").Value = Password
    IEX.Document.Forms("frmUserID").Item("domain").Value = Domain
    IEX.Document.all.Item("submitButton").Click
 
End Sub

Thanks to any who tried to help via PM's. Also good luck to any who might be trying to accomplish something similar.
 

Users who are viewing this thread

Back
Top Bottom