Solved Web Browser Controls : A never ending struggle. (1 Viewer)

KitaYama

Well-known member
Local time
Tomorrow, 08:06
Joined
Jan 6, 2022
Messages
2,348
Sometimes I hate myself for deciding to use web browser control, instead of external apps.

Now that it’s been confirmed that the legacy web browser control cannot display PDFs in Windows 11, I created a form with two Edge browser controls:
  • One to display PDF files
  • One to display a supplier’s website
Because of the limited space on the form, both controls need to be the same size, positioned one on top of the other, and I simply show/hide them as needed.
It sounds straightforward, but I just can’t get it to work properly.

How to reproduce:
  • Extract the ZIP file to a folder and open the database.
  • The control that shows the website (wBrowser) is visible.
  • The control that shows the PDF (pdfBrowser) is hidden.
If you double-click the Detail section:
  • wBrowser gets hidden.
  • pdfBrowser gets visible and the path of one of the attached PDF files is assigned to its RecordSource.
With each double-click on the Detail section, one of three PDFs should be displayed.


The problem:
The PDF does not stay visible. It appears for a second and then disappears.
If anyone has a bit of free time to take a look and point out what I might be doing wrong, I would really appreciate it.

Thanks.
 

Attachments

there is, initially, a control source on your pdf browser (viewer), remove it (unbound).
 
i tried it also and it does work.
I'm sorry, but I don't understand how you think it's working.
In your clip, I don't see the pdfs. Do you see any pdf after double clicking the detail section?
Do you see all three of pdfs when you keep double clicking details section?
 
I modified your code slightly and set tab stop to no - this now works for me.

Must admit, the browser control seems unwilling to swap between a web address and a local file. I suspect there is probably something in the control settings that might fix that
 

Attachments

Must admit, the browser control seems unwilling to swap between a web address and a local file.
I've tried hard to do so, and have failed.
Then asked copilot what I'm doing wrong. According to copilot:
the Edge Web Browser control in Access cannot reliably display both remote websites and local PDF files in the same control because of how the underlying WebView2 engine handles navigation, security zones, and PDF rendering. It’s a limitation of the control itself.
1. WebView2 treats local files differently from web URLs
2. PDF rendering uses a different internal handler
3. Access wraps WebView2 in a simplified control

This machine has Office 2019. I'll test with 356 later and will respond.
Thanks for your time.
 
I modified your code slightly and set tab stop to no - this now works for me.

Must admit, the browser control seems unwilling to swap between a web address and a local file. I suspect there is probably something in the control settings that might fix that
I just tested it with AnyDesk. When I open the form, the web site doesn't show. Does it show for you?
I can confirm that the PDFs show, even though it takes a long time. ( I can live with it)

Once I'm back to my PC, I'll check why the web site is not desplayed. Maybe I can find the problem myself.
Anyhow, thanks for your time and help.


@CJ_London Thanks for your time. It works and shows the result I was trying to achieve.
Appreciate your help.
 
Last edited:
I had similar code back in 2023 that worked at the time but a change since then means it no longer works.

As you probably know, there are several issues that need to be dealt with:
1. Cannot swop between local and online control sources - hence the need for two controls as you have done
2. Cannot navigate from one URL to another unless the URL is saved in a trusted domains table
3. Swopping between browser control using .Visible = False / True no longer works successfully - the page is loaded then disappears almost immediately. I believe its a bug!

Attached is a variation which works for me in both Win 10 & Win 11
Start with Form 1 - you can swop between your PDFs and 3 different web pages

The main change is that both browser controls are always visible but the one not in use is set to .Height=0
I've also added a trusted domains table to both browser controls

Then try my modified version of your Form 2 with similar changes which does now work

EDIT: I haven't studied the last 3 posts
 

Attachments

Last edited:
I had similar code back in 2023 that worked at the time but a change since then means it no longer works.

As you probably know, there are several issues that need to be dealt with:
1. Cannot swop between local and online control sources - hence the need for two controls as you have done
2. Cannot navigate from one URL to another unless the URL is saved in a trusted domains table
3. Swopping between browser control using .Visible = False / True no longer works successfully - the page is loaded then disappears almost immediately. I believe its a bug!

Attached is a variation which works for me in both Win 10 & Win 11
Start with Form 1 - you can swop between your PDFs and 3 different web pages

The main change is that both browser controls are always visible but the one not in use is set to .Height=0
I've also added a trusted domains table to both browser controls

Then try my modified version of your Form 2 with similar changes which does now work

EDIT: I haven't studied the last 3 posts
Am not able to check now, but it seems promissing.
Thanks for sharing.
After checking, will come back again.

Million thanks.
 
it no longer works.
One of the greatest advantages Access had over its competitors, beyond its ease of us, was its consistency. You could build a database and expect it to run flawlessly through multiple generations of Windows and Office updates, performing just as it did on day one.

Lately, however, that confidence has been replaced by uncertainty. Instead of stability, we now worry about what might break with the next update. Each new update brings not anticipation, but concern about what might stop working next.
 
I had similar code back in 2023 that worked at the time but a change since then means it no longer works.

As you probably know, there are several issues that need to be dealt with:
1. Cannot swop between local and online control sources - hence the need for two controls as you have done
2. Cannot navigate from one URL to another unless the URL is saved in a trusted domains table
3. Swopping between browser control using .Visible = False / True no longer works successfully - the page is loaded then disappears almost immediately. I believe its a bug!

Attached is a variation which works for me in both Win 10 & Win 11
Start with Form 1 - you can swop between your PDFs and 3 different web pages

The main change is that both browser controls are always visible but the one not in use is set to .Height=0
I've also added a trusted domains table to both browser controls

Then try my modified version of your Form 2 with similar changes which does now work

EDIT: I haven't studied the last 3 posts
@isladogs
I just tested your database, and I honestly couldn’t believe my eyes. It’s perfect. Aactually, more than perfect.
Because of my monitor size and testing through AnyDesk, I couldn’t dig into the code to see the magic behind it. But the result is exactly what I was hoping to achieve.

I’m not even sure I can wait until tomorrow morning to see how you pulled this off.

A million thanks for your help!
Many, many thanks...
 
You're welcome. Its an approach I've used for the last 2 years when my old code using .Visible=True/False stopped working

I'm still unsure why using resetting the Visible property no longer works properly - either a timing issue or a bug?
Anyway, resetting the Height instead does work reliably.
 
Anyway, resetting the Height instead does work reliably.
@isladogs You may not believe me, but I had already tested that and still couldn’t get the result I needed.
As you can see in my shared database, the pdfBrowser is shorter than the wBrowser. That’s because I was experimenting with changing its height in code to see whether it would make any difference.
I changed the height in both the Open and Load events, but the result was the same. Then I tried changing the height before setting the pdfBrowser’s RecordSource, and again after setting it. Still no change.

But your file works.
And now I understand why my testing failed while yours succeeded.
Let's break your code with a simple change:
Change this line:
pdfBrowser.Height = 8000
to:
pdfBrowser.Height = wBrowser.Height

After that, your form could no longer display the PDFs.
That's the whole reason I couldn't make it work.
Unbelievable. Setting it to a fixed number works, but setting it equal to the height of another control doesn’t.
Microsoft… thank you very much.
 
@Colin: Is MSFT aware of these problems? Apparently there are at least 2 bugs with their preferred browser control.
Points 1 & 2 in my list from post #9 are known limitations imposed for security reasons and are documented in the link provided in that post.

I'm fairly sure, point #3 has been mentioned to the A-team in the distant past, possibly by me. In any case, I'm going to raise it with them in the next day or so.
 
@isladogs You may not believe me, but I had already tested that and still couldn’t get the result I needed.
As you can see in my shared database, the pdfBrowser is shorter than the wBrowser. That’s because I was experimenting with changing its height in code to see whether it would make any difference.
I changed the height in both the Open and Load events, but the result was the same. Then I tried changing the height before setting the pdfBrowser’s RecordSource, and again after setting it. Still no change.

But your file works.
And now I understand why my testing failed while yours succeeded.
Let's break your code with a simple change:
Change this line:
pdfBrowser.Height = 8000
to:
pdfBrowser.Height = wBrowser.Height

After that, your form could no longer display the PDFs.
That's the whole reason I couldn't make it work.
Unbelievable. Setting it to a fixed number works, but setting it equal to the height of another control doesn’t.
Microsoft… thank you very much.
No that isn't correct. You can set the height as you did rather than to a fixed value.
The problem is entirely with making the control visible in the code.

Try this.
Set both browser controls visible in the property sheet and remove your .Visible = True line.
Arrange your pdf browser being the wbrowser control.
Your original form then works with all the other code unchanged.
 
No that isn't correct. You can set the height as you did rather than to a fixed value.
The problem is entirely with making the control visible in the code.

Try this.
Set both browser controls visible in the property sheet and remove your .Visible = True line.
Arrange your pdf browser being the wbrowser control.
Your original form then works with all the other code unchanged.
As I said, I edited your database in #9.
The only edit I did was
Changed this line:
pdfBrowser.Height = 8000
to:
pdfBrowser.Height = wBrowser.Height

Your database stopped working. Give it a try.

I'll follow your instructions in the morning
Thanks again
 

Users who are viewing this thread

Back
Top Bottom