Converting IE access VBA code to work with Edge

wackywoo105

Registered User.
Local time
Yesterday, 22:37
Joined
Mar 14, 2014
Messages
203
I was writing a procedure usingVBA in access to use internet explorer. I have come up against an issue with compatibility which I will not be able to circumvent, and why am I using a depreciated browser?

I had it largely working and am now trying to convert the code to work with an Edge browser form window. I have added an edge browser control to my form.

Code:
Me.EdgeBrowser0.Navigate "https://webpage"

Can anyone help with how to alter the following to work with edge?

Code:
IE.Document.getElementById("PlaceHolderMain_signInControl_UserName").Value = "login"
IE.Document.getElementById("PlaceHolderMain_signInControl_password").Value = "password"
IE.Document.getElementById("PlaceHolderMain_signInControl_login").Click

Code:
Select Case Title
Case "Prof"
IE.Document.getElementById("titleCode").selectedIndex = 1
Case "Sister"
IE.Document.getElementById("titleCode").selectedIndex = 2
Case "Mr"
IE.Document.getElementById("titleCode").selectedIndex = 3
Case "Mrs"
IE.Document.getElementById("titleCode").selectedIndex = 4
End Select

Code:
Do Until IE.ReadyState = 4 And Not IE.Busy
    DoEvents
Loop

I added the extra bit with gettag as sometimes the page wasn't fully loaded before access tried to enter data. I largely seemed to work. Is there a better method with edge?

Code:
x = Timer + 3 'extra bit just to make sure it's fully loaded
    Do While Timer < x
        DoEvents
    Loop
'Do While getTagNumber(IE, "title", "PCSE", 0) = -1
    x = Timer + 1
        Do While Timer < x
        DoEvents
        Loop
    DoEvents
Loop

Code:
' Returns the number of the HTML element specified by tagname and identifying text
Function getTagNumber(IE As InternetExplorer, tagName As String, Optional identifyingText As String, Optional startAtTagNumber As Long = 0) As Long
Dim x As Long
Dim t As Object
For x = startAtTagNumber To IE.Document.all.Length - 1
    Set t = IE.Document.all(x)
        If UCase(t.tagName) = UCase(tagName) Then
            'we found the right kind of tag, check to see if it has the right text
            'Debug.Print t.outerHTML
                If InStr(1, t.outerHTML, identifyingText) > 0 Then
                     'we found the right kind fo tag with the right identifying text, return the number
                      getTagNumber = x
                      Exit Function
                 End If
          End If
Next
getTagNumber = -1 ' sentinal value indicating the tag was not found
End Function

Code:
Dim ClaimNumberTag As Long
ClaimNumberTag = getTagNumber(IE, "strong", "Claim Number", 0)
PCSEGOS1ClaimDate = Format(Now, "dd/mm/yyyy")
If PCSEGOS1ClaimNumber & "" Like "" Then
    PCSEGOS1ClaimNumber = Replace(IE.Document.all(ClaimNumberTag).innerHTML, "Claim Number: ", "")
Else
    PCSEGOS1ClaimNumber = Replace(IE.Document.all(ClaimNumberTag).innerHTML, "Claim Number: ", "") & ", " & PCSEGOS1ClaimNumber
End If
 
Last edited:
Hi, you have been asking a lot of questions regarding completing this webform recently.

From some of your posts, it appears to be an NHS website/intranet site.

Are you working within the NHS?

If so, perhaps get on to the developers to see if they offer an API for performing the operations.

It might be quite possible to do everything you need using HTTP requests and bypass the site entirely.
 
Have you tried setting your IE variable to Me.EdgeBrowser0?
 
I don't work directly for the NHS but this is a portal we use for certain NHS functions. I do have some API documentation somewhere. As for contacting the developers, that would be very difficult, as they don't even respond to general queries.

One day I will have a better look at at the API stuff (and will be here with many questions no doubt) but for now I would like to use the web portal interface. I almost had it working but one of the pages generates a QR code which link to a web page to collect a signature. I can take this base64 QR code, convert it to png, save it and display it in my form. The problem is once the signature has been entered IE doesn't update, so I can't continue. Chrome and Edge both do, so I need to use one of those. I had a look at selenium but from what I read if chrome updates it will stop working until you update the lib file (or whatever it is). It's also quite good to be able to display the webpages in my access form.

I did try something along the lines of changing IE to Me.EdgeBrowser0 and from what I've read it should be almost as simple as that, so I will experiment more.

Are there any decent guides with how to get started using API as this I something I'm not very familiar with?
 
I'm so stupid

got it down to this, which does not generate an error:

Code:
Me.EdgeBrowser0.ExecuteJavascript "document.getElementById(" & Chr(34) & ElementID & Chr(34) & ").value =" & Chr(34) & Login & Chr(34) & ";"

but it wasn't updating. Of course after putting in a delay it worked. I forgot to let the page load first.
 

Users who are viewing this thread

Back
Top Bottom