我正在创建一个 vb.net 程序,我有一个按钮,单击该按钮将浏览 MDB 文件(代码 1),选择后将执行一些代码行,将 access 数据库中的所有宏填充到一个组合中框(代码 2)。我遇到的问题是代码 2 运行后 MSACCESS.EXE 进程没有关闭。我尝试了一些不同的东西,比如 objAccess.CloseCurrentDatabase() 都没有工作。关于我做错了什么有什么想法吗?
代码 1
Private Sub CommandDBPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CommandDBPath.Click
Dim dialog As New OpenFileDialog()
dialog.Filter = "Access database (*.mdb)|*.mdb"
If DialogResult.OK = dialog.ShowDialog Then
TextDBPath.Text = dialog.FileName
End If
SelectDatabaseMacro()
End Sub
代码 2
Private Sub SelectDatabaseMacro()
Dim objAccess As Object '' Access.Application
Dim i As Long
Dim path As String
path = TextDBPath.Text
objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase(path)
For i = 0 To objAccess.CurrentProject.AllMacros.Count - 1
TextReportMacro.Items.Add(objAccess.CurrentProject.AllMacros(i).Name)
Next
objAccess.CloseCurrentDatabase()
objAccess = Nothing
End Sub