Set Magnification for URL in MS Access WebControl Using VB

Chuck Morrison
Chuck Morrison used Ask the Experts™
on
In MS Access, I have a webcontrol on a form.  I want to be able to force magnification for the URL to 125 percent.  I have found several articles on Google about this, but nothing seems to work for me.  Here is what I have now - the last line represents the best suggestion I was able to find on the intrawebs:

DoCmd.OpenForm "WebBrowser", acNormal
DoCmd.Maximize
       
Forms!WebBrowser.RecordSource = "Wordpress"
    Forms!WebBrowser.Filter = "[Select]=-1"
    Forms!WebBrowser.FilterOn = True

'''''  the URL comes from tbWordpress from either be in Site, NewPost or NewPage in the Wordpress table
    Forms!WebBrowser!WebBrowser0.ControlSource = "NewPost"
   
   
    Forms!WebBrowser!WebBrowser0.ExecWB OLECMDID_OPTICAL_ZOOM, ExecOpt.OLECMDEXECOPT_DONTPROMPTUSER, 150, DBNull.Value
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fabrice LambertConsulting
Distinguished Expert 2017

Commented:
Hmm, instead of using akward API calls, what about using a textbox right above the webbrowser control ?

Simply configure the texbox in design mode, have VBA update its data, and you're done.
Chuck MorrisonIndependent Consultant (Healthcare)

Author

Commented:
Text box for what?  The URL?  The zoom level?
Fabrice LambertConsulting
Distinguished Expert 2017

Commented:
For the URL of course.
Choose a font and its size matching your needs, and never ever touch it again.
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Chuck MorrisonIndependent Consultant (Healthcare)

Author

Commented:
The URL for the WebBrowser control is variable as is (possibly) the magnification, so I can't set and forget.  The control needs to be magnified not the URL.  Some webpages will need to be 125%, some will need to be 75%.  I need help understanding how putting a URL in a text box with a specific font is going to change the magnification in the control?
Fabrice LambertConsulting
Distinguished Expert 2017

Commented:
So, this is the control, not the URL.
I want to be able to force magnification for the URL to 125 percent.
Ehence the confusion.
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
This works for me:

Private Sub SetZoomLevel(Optional ByVal InOut As Long)

    Const DefaultZoomLevel  As Long = 0
    Const MinimumZoomLevel  As Long = -2
    Const MaximumZoomLevel  As Long = 2
    Const ZoomOffset        As Long = 2

    Static CurrentZoomLevel As Long
    
    Dim ZoomLevel           As Long
    
    Select Case Sgn(InOut)
        Case 1
            If CurrentZoomLevel < MaximumZoomLevel Then
                CurrentZoomLevel = CurrentZoomLevel + 1
            End If
        Case -1
            If CurrentZoomLevel > MinimumZoomLevel Then
                CurrentZoomLevel = CurrentZoomLevel - 1
            End If
        Case 0
            CurrentZoomLevel = DefaultZoomLevel
    End Select
    
    ZoomLevel = CurrentZoomLevel + ZoomOffset
    
    Me!Webbrowser0.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, (ZoomLevel)

End Sub

Private Sub ZoomIn_Click()

    SetZoomLevel 1

End Sub

Private Sub ZoomOut_Click()

    SetZoomLevel -1

End Sub

Private Sub ZoomZero_Click()

    SetZoomLevel

End Sub

Open in new window

The trick is (ZoomLevel) which forces a read-only value to be passed.

Note however, that the zoom effect may not be what you expect; it only adjusts the size of the fonts and these will on many sites be supervised by the page itselft, not this setting.

See the attached demo.
Zoom.accdb

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial