如果存在重复,则文 本框撤消不起作用

问题描述 投票:-1回答:2

我有一个带有文本框和列表框的表单。我想在文本框中输入一条新记录来填充表和列表框(列表框行源是表)。我编写了一个代码来防止重复进入表。当有重复的条目时,我会弹出一个提醒用户。什么不起作用是清除文本框的撤消选项。代码粘贴在下面,带有一些必要的信息。任何有关代码的帮助将不胜感激。

表名:tblNewComponents

字段名称:NewComponents

文本框名称:TextCOMPONENTS

有人能帮我吗?谢谢

Private Sub TextCOMPONENTS_AfterUpdate()
Dim NewComponent As String
Dim stLinkCriteria As String
Dim custNo As Integer
'Assign the entered customer name to a variable NewCustomer
NewComponent = Me.TextCOMPONENTS.Value
stLinkCriteria = "[NewComponents] = " & "'" & NewComponent & "'"
If Me.TextCOMPONENTS = DLookup("[NewComponents]", "tblNewComponents",     stLinkCriteria) Then
MsgBox "This Component, " & NewComponent & ", has already been entered in    database." _
& vbCr & vbCr & "Please check the component name again.", vbInformation, "Duplicate information"
Me.Undo
end if
exit sub
ms-access access-vba ms-access-2010 ms-access-2007 ms-access-2016
2个回答
0
投票

只需这样做就可以清除文本框(并将焦点设置到文本框中)

Me.TextCOMPONENTS.Value = Null
Me.TextCOMPONENTS.SetFocus

而不是Me.Undo


0
投票

你的错误发生在你的事件行为中,你应该将它保存在下一个文本框的gotfocus事件中,而不是在当前文本框中更新后,在下一个文本框的gotfocus事件中,并且将完美地工作。非常感谢SOF俱乐部

© www.soinside.com 2019 - 2024. All rights reserved.