访问VBA打开新表单上的所有记录,但显示指定的记录

时间:2013-06-12 14:18:53

标签: vba ms-access records openform

我有一个带有身份证号码的表格,以及应该用相关记录打开另一张表格的按钮。除了显示的特定记录之外,我还需要打开所有记录,因为我的表单需要有Next和Previous按钮。我已经尝试了几天了,而且我无法打开所有记录并同时显示特定的一项工作。所以我在这里开始使用向导打开所有记录。我该如何修复它以显示点击的记录?

Private Sub Command74_Click()

On Error GoTo Err_Go_to_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Contracts"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Go_to_Click:
    Exit Sub

Err_Go_to_Click:
    MsgBox Err.Description
    Resume Exit_Go_to_Click


End Sub

提前致谢!

1 个答案:

答案 0 :(得分:1)

打开表单后,您需要导航到正确的记录。 我没有看到填充stLinkCriteria的代码,因此我在我的示例中提供了一些虚拟数据。

Private Sub Command74_Click()

On Error GoTo Err_Go_to_Click

Dim stDocName As String
Dim stLinkCriteria As String

stLinkCriteria = "ContactID = '" & Me.ContactID & "'"
stDocName = "Contracts"
'Open the form with no filter
DoCmd.OpenForm stDocName
'Go to the specified record
Forms(stDocName).Recordset.FindFirst stLinkCriteria

Exit_Go_to_Click:
    Exit Sub

Err_Go_to_Click:
    MsgBox Err.Description
    Resume Exit_Go_to_Click


End Sub