怎樣打開外部數(shù)據(jù)庫中的報(bào)表

字號(hào):

access 97 以后的版本給了我們一個(gè)新的方法: OpenCurrentDatabase, 下列代碼將使用這種方法來實(shí)現(xiàn)打開外部數(shù)據(jù)庫中的報(bào)表。
    Private Declare Function apiSetForegroundWindow Lib "user32" _
    Alias "SetForegroundWindow" _
    (ByVal hwnd As Long) _
    As Long
    Private Declare Function apiShowWindow Lib "user32" _
    Alias "ShowWindow" _
    (ByVal hwnd As Long, _
    ByVal nCmdShow As Long) _
    As Long
    Private Const SW_MAXIMIZE = 3
    Private Const SW_NORMAL = 1
    Function fOpenRemoteReport(strMDB As String, strReport As String, _
    Optional intView As Variant) _
    As Boolean
    ' strMDB: 外部數(shù)據(jù)庫名稱(含路徑)
    ' strReport: 報(bào)表名稱
    ' intView: 報(bào)表的打開方式
    Dim objAccess As access.Application
    Dim lngRet As Long
    On Error GoTo fOpenRemoteReport_Err
    If IsMissing(intView) Then intView = acViewPreview
    If Len(Dir(strMDB)) > 0 Then
    Set objAccess = New access.Application
    With objaccess
    lngRet = apiSetForegroundWindow(.hWndaccessApp)
    lngRet = apiShowWindow(.hWndaccessApp, SW_NORMAL)
    ' 第一次調(diào)用ShowWindow似乎不做任何事情
    lngRet = apiShowWindow(.hWndaccessApp, SW_NORMAL)
    .OpenCurrentDatabase strMDB
    .DoCmd.OpenReport strReport, intView
    Do While Len(.CurrentDb.Name) > 0
    DoEvents
    Loop
    End With
    End If