Office中国论坛/Access中国论坛

标题: 用代码打开外部MDB的几种方法 [打印本页]

作者: andymark    时间: 2006-11-6 22:15
标题: 用代码打开外部MDB的几种方法


方法1:
   
    Dim AccessPath As String
    Dim DbPath As String

    AccessPath = SysCmd(acSysCmdAccessDir) & "MSACCESS.EXE"
    DbPath = "C:\db1.mdb"
    Shell AccessPath & " " & DbPath

方法2:
   
    Dim DbPath As String

    DbPath = "C:\db1.mdb"
    Application.FollowHyperlink DbPath

方法3:
     
     Private Declare Function ShellExecute Lib "shell32.dll" _
                Alias "ShellExecuteA" _
                (ByVal hwnd As Long, _
                ByVal lpOperation As String, _
                ByVal lpFile As String, _
                ByVal lpParameters As String, _
                ByVal lpDirectory As String, _
                ByVal nShowCmd As Long) As Long

    Sub OpenBd()
    Dim DbPath As String

    DbPath = "C:\db1.mdb"
    ShellExecute 0&, vbNullString, DbPath, vbNullString, vbNullString, 0&
   
    End Sub

方法4:
   
   Dim DbPath As String
   Dim oApp As Access.Application

    DbPath = "c:\db1.mdb"
   
    Set oApp = New Access.Application
   
    With oApp
        
        .Visible = True
        
        .OpenCurrentDatabase DbPath
        
        .DoCmd.OpenForm "MyForm"
        
        .DoCmd.OpenReport "MyReport", acViewPreview
        
        .Run "MyFuncion"
    End With
   
    Set oApp = Nothing

[此贴子已经被作者于2006-11-6 14:16:41编辑过]


作者: 好学    时间: 2006-11-6 23:12
andymark版主的都是好方法!收藏了。
作者: zhycfb2006    时间: 2006-11-7 04:59
能告诉一下具体的操作过程吗?

谢谢!
作者: c101    时间: 2009-10-20 20:15
謝謝




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3