【发布时间】:2019-07-05 01:25:14
【问题描述】:
我正在处理我负责处理的工作问题。在 Excel 工作表中有一个 ID 列表和一个 MS Access 数据库,其中包含与这些记录对应的记录。我需要编写代码来打开一个访问表单,以访问从 excel 字段中识别的记录。
Sub OpenAccess()
Dim LPath As String
Dim StudentID As Integer
'Path to Access database
LPath = "C:\Users\Admin\Desktop\CNRC_Test.accdb"
'Open Access and make visible
Set oApp = CreateObject("Access.Application")
oApp.Visible = True
'Open Access database as defined by LPath variable
oApp.OpenCurrentDatabase LPath
'Open form called Categories filtering by CategoryID
oApp.DoCmd.OpenForm "Student Details", , , "Student ID=" & StudentID
End Sub
我试过这段代码:
Sub OpenAccess()
Dim LPath As String
Dim StudentID As Integer
'Path to Access database
LPath = "C:\Users\Admin\Desktop\CNRC_Test.accdb"
'Open Access and make visible
Set oApp = CreateObject("Access.Application")
oApp.Visible = True
'Open Access database as defined by LPath variable
oApp.OpenCurrentDatabase LPath
'Open form called Categories filtering by CategoryID
oApp.DoCmd.OpenForm "Student Details", , , "Student ID=" & StudentID
End Sub
【问题讨论】:
-
有什么问题?描述错误或您有什么问题?另外,您使用的是什么 excel 和 access 版本?
-
Office 2016 代码打开访问表单,但不是通过单击 Excel 单元格或转到 Excel 单元格指定的记录。我需要打开对单击的 excel 单元格指定的记录的访问表单。