我有一个带有外部数据库 (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
我也考虑过使用记录集并将其与备忘录字段进行比较,但这也失败了。感谢您对此的任何意见或帮助。也许我只是错误地接近它
标记