VBA code to automate Internet explorer VIA if function (1 Viewer)


Registered User.
Sep 20, 2007
I have VBA code that opens up a specific intranet webpage depending on the reference number, is there a way to do a VBA if statement that if a specific sentence is shown in the body of the website then it does a certain task, e.g. automatically closes the IE webpage and shows a popup message on Access saying incorrect Ref number?

Basically when the incorrect REF is given in the body of the website it reads REF ERROR, which is ideally like VBA to automatically close the website and show a popup in Access

Dim IE As Object   
Create InternetExplorer Object
Set IE = New InternetExplorerMedium
With IE
.Visible = True
.navigate "http://corp/rf/ViewDetail.asp?Headerid=" & Mid([Forms]![FRMALLDetails]![SFRMHRDetails]. [Form]![Ref], 3, 8)
End With

For Each win In CreateObject("Shell.Application").Windows
If win.Name Like "*Internet Explorer" Then
    Set IE = win: Exit For
End If

'Wait for IE to load
With IE
Do Until .ReadyState = 4

End With
End Function
Yes, it should be possible, you need to identify the document element that returns the error and based on its value close the page or not.
If IE.GetElementByID("ErrorElement").Value = "REF ERROR" Then...

Users who are viewing this thread

Top Bottom