我有一个包含文本框的访问表单,我需要检查它的最后一个单词,并且如果该单词是许多单词(数组或表列)之一,请执行操作,并且此检查将在after_update事件中进行,例如
Private Sub textbox_AfterUpdate()
Dim txt As String
Dim lastword As String
txt = TextBox.Value
lastword= Right(txt, Len(txt) - InStrRev(txt, " "))
if lastword in (array() or column in a table) then
' do an action
End If
End Sub
我们还可以为我们提供外部功能,您能帮我吗?
看起来您已经获得了最后一个单词的功能...现在在数组和表中进行搜索可使用以下命令:
Function isInArray(stringToBeFound As String, arr As Variant) As Boolean
IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
End Function
和
Function isColumnName(stringToBeFound As String, tableName As String) As Boolean
Dim db As Database
Dim rs1 As DAO.Recordset
Set db = CurrentDb()
Set rs1 = db.OpenRecordset(tableName)
isColumnName = False
Dim fld As DAO.Field
do until rs1.EOF
if rs1.Fields.Item(0).Value = stringToBeFound then
isColumnName = true
exit loop
end if
rs1.moveNext
loop
Set fld = Nothing
End Function
用法:
if isInArray(lastWord, youArray) or isColumnName(lastWord, "yourTable")
MsgBox "The word is already used!"
end if
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句