vba - 突出显示在表单字段文本框中找到的匹配字符串,来自表格或静态数组(使用 MS Access)
问题描述
我有一个带有外部数据库 (ODBC) 连接的 Access 工具/数据库。它的目的是查看呼叫日志中的问题,用户将根据消息的内容决定严重程度。
我有一个想法,使用 VBA 来协助审查。我用大约 50 个字符串创建了一个,并将其与表单(绑定到表格列)中的字段(备忘录格式)进行比较。我希望例程只突出显示字符串的匹配部分。
一个例子是:
如果数组字符串包含“Repor”,它将仅更改备注字段中的那些字母的字体大小和颜色 Like Reported , 。更大的字体和不同的颜色
我可以使用下面的这段代码在 Excel VBA 中成功地做到这一点(“findar”是一个预先构建的数组,rng1 是指定的范围)
For i = LBound(findar) To UBound(findar)
For Each rngcell In rng1
startPos = 0
startPos = InStr(rngcell, findar(i))
If InStr(rngcell, findar(i)) <> 0 Then
rngcell.Characters(startPos, Len(findar(i))).Font.Color = vbBlue
rngcell.Characters(startPos, Len(findar(i))).Font.Size = 18
End If
Next rngcell
Next I
“字符”,显然在 Access 中不存在,所以我正在尝试这个,在“获得焦点”事件中触发:它失败并出现运行时错误 13。我确定这是可行的,但显然不是我.. ...
Dim i As Integer
Dim startpos As Long
'findar is an array
'incident text is inside the form field
findar = Array("returned", "failed") 'real array is about 50 strings
inctext = Me.txtincidentdesc
lngred = RGB(255, 0, 0)
lngblack = RGB(0, 0, 0)
'reset to default
Me.txtincidentdesc.FontBold = False
Me.txtincidentdesc.ForeColor = lngblack
Me.txtincidentdesc.FontSize = 10
startpos = 0
For i = LBound(findar) To UBound(findar)
With Me.txtincidentdesc
If InStr(inctext, findar(i)) <> 0 Then
SelStart = InStr(inctext, findar(i))
SelLength = Len(findar(i))
txtincidentdesc(Mid(inctext, SelStart, SelLength)).ForeColor = lngred 'fails here RunTime error 13
' Me.txtincidentdesc.ForeColor = lngred ' this works fine
' Me.txtincidentdesc.FontSize = 20 'this works fine
End If
End With
Next
End Sub
我也考虑过使用记录集并将其与备忘录字段进行比较,但这也失败了。感谢您对此的任何意见或帮助。也许我只是错误地接近它
标记
解决方案
推荐阅读
- python - 链接 subprocess.Popen 以模拟管道
- ruby-on-rails - Ruby rest-client gem 总是导致 OpenTimeout
- python - 无法在 Python 中打印不同字典的多个键
- javascript - 通过 express js 和 javascript 获取 html 文件时出错
- php - PHP 数值数据验证
- c# - EF Core - 2 个实体,每个实体都引用另一个查找实体。添加时 - IOE - 无法跟踪,因为另一个具有键值的实例
- javascript - Chrome 开发者控制台不会将数字推送到我创建的数组中
- c++ - HttpSendRequestA 为假并返回 0
- nginx - 我可以配置 nginx-ingress 将流量路由到集群外部吗
- google-assistant-sdk - 带 Google 助理的 Respeaker Core v2.0