【问题标题】:Access vba - code for opening and closing a Internet Explorer Window - running in different proceduresAccess vba - 打开和关闭 Internet Explorer 窗口的代码 - 在不同的过程中运行
【发布时间】:2016-03-10 23:23:29
【问题描述】:

我被要求创建一个访问数据库,该数据库一次读取一条记录,并显示相关的网站。那么在用户更改了一些数据,并移动到下一条记录之后,我要确保网站已经关闭,然后再打开新的,以确保用户不会误看错误的网站。

到目前为止,我声明了一个公共变量来操纵浏览器窗​​口(首先作为一个对象,然后专门作为一个 Internet Explorer 对象),使用可见、导航和忙碌命令通过公共子安全地打开网站,这个sub 在表单加载和表单当前都被调用,然后最后尝试关闭窗口,在表单当前,使用退出命令。见下文。

    Public IEtest As InternetExplorer

    Public Sub OpenIE(strURL As String)

    Set IEtest = New InternetExplorer

    IEtest.Visible = True
    IEtest.Navigate strURL

    While IEtest.Busy
        DoEvents
    Wend

    End Sub

    Private Sub Form_Current()
    With IEtest
            .Visible = False
            .Quit
    End With

    Call OpenIE(Me.Imagelink)
    end sub

我的问题是退出命令正在执行:加载表单时第一次没有任何内容;然后在移动到新记录时,我收到自动化错误 2147417848 -...与客户端断开连接...

我做错了什么?你能给我代码来做到最好吗?

【问题讨论】:

    标签: vba internet-explorer navigation ms-access-2010


    【解决方案1】:

    这正在工作,解决方案是:

          Public IEtest As InternetExplorer
    
          Public Sub OpenIE(strURL As String)
    
           Set IEtest = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
    
          With IEtest
              .Visible = True
              .Navigate strURL
              .AddressBar = True
              .MenuBar = True
              .StatusBar = True
              .Toolbar = True
              .Height = 860
              .Width = 1430
              .Left = 1
              .Top = 1
    
              While .Busy
                  DoEvents
              Wend
          End With
    
      End Sub
    
    Private Sub Form_Current()
        On Error Resume Next
        IEtest.Quit
    
        If Not IsNull(Me.Imagelink) Then
            Call OpenIE(Me.Imagelink)
        End If
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2017-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-25
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      相关资源
      最近更新 更多