Results 1 to 3 of 3
  1. #1
    ino_mart is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    16

    Display html in webbrowser control: Run-time error 91, object variable or With block variable not se

    All

    I have a form on which I placed a webbrowser control. On the "On current"-event procedure below runs, but it errors on link "oHTMLDoc.open" with Run-time error 91, object variable or With block variable not set

    I did enable reference Microsoft HTML Object Library



    Code:
    Private Sub ToonFotos()Dim strSQL As String
    Dim rs As Recordset
    Dim strOutput As String
    Dim oWebBrowser As Object
    Dim oWebBrowserObject As Object
    Dim oHTMLDoc As MSHTML.HTMLDocument
    
    
    strSQL = "select [pad] from qryGerechtFoto" ' where [gerecht_fk]=" & Me.Teller
    Set rs = CurrentDb.OpenRecordset(strSQL)
    strOutput = "<html>"
    If Not rs.BOF And Not rs.EOF Then
        strOutput = strOutput & "<table><tr>"
        While Not rs.BOF And Not rs.EOF
            strOutput = strOutput & "<td>" & rs!pad & "</td>"
            rs.MoveNext
        Wend
    End If
    
    
    Set oWebBrowser = Me.WebBrowser
    Set oWebBrowserObject = oWebBrowser.Object
    Set oHTMLDoc = oWebBrowserObject.Document
    oHTMLDoc.Open "text/html", "replace"
    oHTMLDoc.Document.write = strOutput
    oHTMLDoc.Close
    End Sub
    Someone an idea how to solve this?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,012
    Check you actually have something in those objects?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    ino_mart is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    16
    After some more investigation, it seems I must initialize the component which can e.g. be done by setting the controlsource to "about:blank". So I solved it by using next code

    Code:
    Me.WebBrowser.ControlSource = "about:blank"
    With Me.WebBrowser.Object.Document
        .Open
        .write strOutput
        .Close
    End With

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 03-19-2020, 01:53 PM
  2. Replies: 2
    Last Post: 07-23-2019, 01:37 PM
  3. Error 91 Object Variable or Block Variable Not Set
    By mindbender in forum Programming
    Replies: 5
    Last Post: 05-01-2017, 12:01 PM
  4. Replies: 6
    Last Post: 02-11-2016, 02:05 PM
  5. Replies: 0
    Last Post: 08-10-2011, 11:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums