Cannot run web page login code using the Edge browser control (1 Viewer)

KitaYama

Well-known member
Local time
Tomorrow, 06:52
Joined
Jan 6, 2022
Messages
2,348
These changes hurt so much.
We could have a legacy web control and set it to a specific internet site. Then in form's Load event, run a vba code to set a value in username & password of the site and click a button to login.
If necessary, users could tick a checkbox to show the local pdf of the selected record in the same browser.

Now we should have 2 browsers, one on top of the other. and hide one of them and show the other base on the situation.
We have to show legacy browser for the site and login, and when the user needs to see a local file, click a button to hide the legacy and show the new web browser.
We couldn't find a way to login automatically in new web browser.
Or
Find a way to show local pdf files in the legacy browser.
 
@KitaYama
I'll contact the Access team again later today to check if there is any progress on the issue with PDFs in the legacy browser control.

Before I do so, can you elaborate on the issues with logging into a website with a user name & password in the Edge browser control.
Its not something I've ever needed to do so I don't have an example to test with
Do you have something you could upload for me to use for testing (using either browser control).
 
Last edited:
@KitaYama
I'll contact the Access team again later today to check if there is any progress on the issue with PDFs in the legacy browser control.

Before I do so, can you elaborate on the issues with logging into a website with a user name & password in the Edge browser control.
Its not something I've ever needed to do so I don't have an example to test with
Do you have something you could upload for me to use for testing (using either browser control).
While I can't share the accdb, I can confirm that with the legacy browser control I used to be able to log in to a site. I asked Claude AI for a version that would use JS to log in with the Edge browser control, but I failed to get it to work. Fortunately, it's not that big of a deal in this instance and now I just let the Browser control load and then log in manually a couple of times a week when I need to. The browser does remember by my credentials to make it easier.

The point is, it's a whole different ballgame code-wise and more than a little PITA and I would be displeased if I had to support clients' usage.
 
This is a very simplified version of something you can work with in legacy web browser.
The form has a web browser control that opens a web site. The target page has two textboxes and a button to click for login.
Form's on-load event calls Kedi_LogUserIn. The textboxes are filled and the button is clicked. User doesn't need to do anything. This works in legacy browser. After more than a week, neither Copilot nor Chatgpt could offer a code that can do the same in modern web browser.

SQL:
Option Compare Database
Option Explicit

Private Browser As Object

Public Function SetBrowser(frm As Access.Form)
    Set Browser = frm.wBrowser.Object
End Function

Public Sub Kedi_LogUserIn(frm As Access.Form)
    If Browser Is Nothing Then
        SetBrowser frm
    End If
 
    With Browser
        Do While .Busy Or .ReadyState <> 4
            DoEvents
        Loop
        .Document.all.Item("USER_ID").Value = "********"
        .Document.all.Item("PASS_WD").Value = "**********"
        .Document.all.Item("Login_Button").Click
    End With

End Sub

Public Sub CloseBrowser()
    Set Browser = Nothing
End Sub

Form's event:
SQL:
Private Sub Form_Load()
    Kedi_LogUserIn Me
End Sub

Private Sub Form_Close()
     CloseBrowser
End Sub
 
Last edited:
Many thanks. Looks straightforward enough.
I’ll test it using the legacy browser control and assuming that works, I’ll then try adapting it for the Edge browser control

If anyone else has got similar code to work using the Edge browser control then I’d like to hear about it … and I’m sure @KitaYama would like to know as well. 😀
 
This is a very simplified version of something you can work with in legacy web browser.
The form has a web browser control that opens a web site. The target page has two textboxes and a button to click for login.
Form's on-load event calls Kedi_LogUserIn. The textboxes are filled and the button is clicked. User doesn't need to do anything. This works in legacy browser. After more than a week, neither Copilot nor Chatgpt could offer a code that can do the same in modern web browser.

SQL:
Option Compare Database
Option Explicit

Private Browser As Object

Public Function SetBrowser(frm As Access.Form)
    Set Browser = frm.wBrowser.Object
End Function

Public Sub Kedi_LogUserIn(frm As Access.Form)
    If Browser Is Nothing Then
        SetBrowser frm
    End If
 
    With Browser
        Do While .Busy Or .ReadyState <> 4
            DoEvents
        Loop
        .Document.all.Item("USER_ID").Value = "********"
        .Document.all.Item("PASS_WD").Value = "**********"
        .Document.all.Item("Login_Button").Click
    End With

End Sub

Public Sub CloseBrowser()
    Set Browser = Nothing
End Sub

Form's event:
SQL:
Private Sub Form_Load()
    Kedi_LogUserIn Me
End Sub

Private Sub Form_Close()
     CloseBrowser
End Sub
Yo have to use JavaScript to "talk" to new Edge Browser.
Try something like this as starting point:


Code:
Option Compare Database
Option Explicit
' Using generic Control to avoid "Type Not Defined" errors
Private BrowserControl As Access.Control

Public Sub Kedi_LogUserIn(frm As Access.Form)
    If BrowserControl Is Nothing Then
        SetBrowser frm
    End If
 
    Dim jsCode As String
 
    ' JavaScript is the only way to talk to the New Browser

    jsCode = "document.getElementById('USER_ID').value = '********';" & _
             "document.getElementById('PASS_WD').value = '**********';" & _
             "document.getElementById('Login_Button').click();"

    ' Using .Object to access the Edge-specific ExecuteJavascript method
    On Error Resume Next
    BrowserControl.ExecuteJavascript jsCode
 
    If Err.Number <> 0 Then
        MsgBox "Could not execute login script. Ensure the page is fully loaded.", vbInformation
    End If
    On Error GoTo 0
End Sub
 
Last edited:
@xavier.batlle
Answering from an Edge browser control in Access!
Yes, you need to use Javascript for the Edge browser control but also need to avoid using .Object as that isn't available in the Edge control
 
Experimenting with logging into this site using an Edge browser control
The code enters my user name & password correctly but the login button doesn't get clicked

Not sure if that's because there are 2 alternative buttons that can be clicked to login or if the site is blocking automated logins
 
@xavier.batlle
Answering from an Edge browser control in Access!
Yes, you need to use Javascript for the Edge browser control but also need to avoid using .Object as that isn't available in the Edge control
I don't use the Edge WebBrowser control, but I tested it when I watched this interesting video by Richard Rost:
 
I've tried multiple different variations of the Edge browser control. None actually click the Login button.
It may well be that this site is blocking automated login clicks
@Jon would be the one who could definitively answer that

For now I'm putting this to one side. Perhaps, tomorrow I'll try some other sites
Bearing in mind neither @KitaYama nor @GPGeorge were successful, it seems there is a more widespread problem
 
I've never been able to share a database here. Here's the reason.
But I give it another try.
If you can open the form in the shared database bellow and are not receiving errors, you will see the following page. It shows that you were able to input a username and a password and clicked the button of a login page, but your credential is not correct and login failed.
If you input the correct username/password, login will be successful and you'll see customer page.

2026-02-17_07-50-13.png


Unfortunately I can not share the correct username and pass and I'm sure you understand why.
As a further test, if you delete the following line, you'll see the textboxes are filled.
.Document.all.Item("Login_Button").Click

If you receive errors on the form, you may need to export the form as text, edit the names and any strange character and import it again.
If you still don't have luck with it, you may want to reconstruct the form in a new database. If so, add the web browser control by using the following button and change the name to www and import the vba code for events and the module.

2.png


This doesn't work if I change the browser to New Browser control. I've been trying to solve the problem with different AIs for days but nothing happens. Any possible solution, javascript included has been tested and returned negative.
 

Attachments

@KitaYama
Very strange. What you provided is exactly what I made after your PM earlier
However this time it worked exactly as expected. No idea why it didn't for me earlier

Not only that but with almost no changes to the code, it also works for that web login page with the Edge browser control (attached)
Can you check with the correct userID / password combination. Thanks

===================================================
EDIT:
This thread is now getting very muddled with two unrelated conversations going on and would be better split.
Tomorrow I'll ask one of the mods to move all the posts about login forms starting with post #20 to a different thread.
I think that's posts 20, 22 to 27, 30 to 32 and 34 (this one).
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom