Dim appAccess As Access.Application
Dim db As Database
Private Sub OpenDB()
Dim strDB As String
' 将字符串初始化为数据库的路径。
strDB = CurrentProject.Path & "\db2.mdb"
' 创建 Microsoft Access 的实例。
Set appAccess = CreateObject("Access.Application")
' 在 Microsoft Access 窗口中打开数据库。
Set db = appAccess.DBEngine.OpenDatabase(strDB, False, False, "WD=123")
appAccess.OpenCurrentDatabase strDB
appAccess.DoCmd.OpenForm "form1"
appAccess.Visible = True
End Sub
****************************
在ACCESSXP下的更简洁:
Private Sub Command0_Click()
Dim App1 As Object
Set App1 = CreateObject("Access.Application")
Dim strURL As String
strURL = CurrentProject.Path & "\1.mdb"
App1.OpenCurrentDatabase strURL, , "123"
App1.DoCmd.OpenForm "窗体1"
App1.Visible = True