我正在尝试移动到具有特定 ID 的记录。
我在这篇文章中尝试了解决方案:MS Access search for record by textbox instead of dropdown
但没有成功
这是我的代码
Private Sub btnShowPrevious_Click()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[ID]=" & ParentID
If rs.NoMatch Then
MsgBox "Sorry, no such record '" & ParentID & "' was found.", _
vbOKOnly + vbInformation
Else
Me.Recordset.Bookmark = rs.Bookmark
End If
rs.Close
End Sub
它总是没有匹配,但 parentID = 1 并且有一条 ID = 1 的记录..
有人知道出了什么问题吗?
谢谢
记录来源是这张表:
CREATE TABLE [dbo].[ProposalFollowUp](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ProposalID] [int] NOT NULL,
[MillID] [int] NULL,
[ClientID] [int] NULL,
[Comment] [nvarchar](max) NULL,
[Method] [nvarchar](128) NULL,
[Contact] [int] NULL,
[ContactDate] [datetime] NULL,
[Done] [bit] NOT NULL,
[CreatedBy] [nvarchar](50) NULL,
[CreatedDate] [datetime] NULL,
[ModifiedBy] [nvarchar](50) NULL,
[ModifiedDate] [datetime] NULL,
[EAIEmployee] [nvarchar](50) NULL,
[PersonInCharge] [nvarchar](50) NULL,
[ParentID] [int] NULL,
这是表单属性的屏幕截图
最后,如果我显示导航栏,我可以看到有一个过滤器。可能是因为我这样打开表格
DoCmd.OpenForm "ProposalsFollowUp", , , "[ID] = " & txtID, acFormEdit, acDialog
如果我删除过滤器,它可以工作。
好的,这是最终的代码
Private Sub btnShowPrevious_Click()
Dim parent As Integer
parent = ParentID
Me.Filter = ""
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[ID]=" & parent
If rs.NoMatch Then
MsgBox "Sorry, no such record '" & parent & "' was found.", _
vbOKOnly + vbInformation
Else
Me.Recordset.Bookmark = rs.Bookmark
End If
rs.Close
End Sub