Hightling并在Access 2010中的备注字段中查找下一个匹配搜索 [英] Hightling and finding the next match search in a memo field in Access 2010
问题描述
我一直在使用这个程序,因为它在10月份在这里得到了解决,但我不能让它做我需要的。我正在备忘录字段中搜索文本,并希望突出显示结果。然后,我希望能够找到
搜索文本的下一次出现,并且理论上也要突出显示那个,依此类推。 我似乎找到了第一个,但最初没有突出显示。相反,输入框会询问您是否要查找更多内容。如果你说好的,它似乎停止了,没有找到第二个
发生。只是,现在您看到突出显示的文本的第一个实例。此外,我已将备忘录字段更改为Rich Text,但似乎无法获得< b>文字< / b>或下划线标记工作。 这是snippit:
Private Sub cmdFind_Click()
'声明程序变量
&NBSP; Dim strText As String
Dim intCharPositionFound As Integer
Dim dbs As DAO.Database
Dim rst as DAO.Recordset
设置dbs = CurrentDb
设置rst = dbs.OpenRecordset(" tblfindings")
'获取要从用户搜索的文字
strText = InputBox("输入要在Notes字段中查找的文本。")
如果strText =""然后
退出子
结束如果是
Do While Not rst.NoMatch为
intCharPositionFound = InStr([查找续],strText)
如果intCharPositionFound> 0然后
'使用txtNotes
使用[继续查找]
.SetFocus
.SelStart = intCharPositionFound - 1
.SelLength = Len(strText)
结束与$
结束如果是
MsgBox"你想找到更多",vbOKCancel,"亮点"
rst.FindNext" [Finding Continued] like""" * strText *"""
Debug.Print strText
循环
End Sub
Dean J. Waring
你的意思是你想在richText Box中突出显示字符串吗?如果是这样,我建议您尝试以下内容:
Private Sub Command11_Click()
'声明程序变量
Dim strText As String
Dim intCharPositionFound As Integer
'获取要从用户搜索的文本
strText = InputBox(&"输入要在Notes字段中查找的文本。")
如果strText =""然后
退出Sub
结束如果
intCharPositionFound = InStr(Me.UserNote,strText)
Me.UserNote.SetFocus
如果intCharPositionFound> 0然后
Me.UserNote.Text =替换(Me.UserNote.Text,strText,"< strong>" + strText +"< / strong>",1,1)
结束如果
响应= MsgBox("是否要查找更多","vbOKCancel","突出显示")
如果Response = vbOK然后'用户选择是。
Me.UserNote.Text = Replace(Me.UserNote.Text,strText,"< strong>" + strText +"< / strong>")
End if
Debug.Print strText
End Sub
Private Sub Command12_Click()
Me.UserNote.SetFocus
Me.UserNote.Text = Replace(Me.UserNote.Text ,"< strong>","")
Me.UserNote.Text = Replace(Me.UserNote.Text,"< / strong>","")
结束子
最好的问候,
Edward
I have been working with this procedure since it was solved in here back in October, but I can't get it to do what I need. I'm searching for text in a memo field and want to highlight the results. Then, I want to be able to find the next occurrence of the search text and, in theory, highlight that one as well and so on and on. I seem to find the first one but it is not highlighted at first. Rather, the Input box asks if you want to find more. If you say ok, it just seems to stop, not finding the second occurrence. Only, now do you see the highlighted first instance of your text. Also, I have changed the memo field to Rich Text but can not seem to get the <b>text</b> or underline tags to work. Here is the snippit:
Private Sub cmdFind_Click()
'Declare procedure variables
Dim strText As String
Dim intCharPositionFound As Integer
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblfindings")
'Get text to search for from user
strText = InputBox("Enter text to find in Notes field.")
If strText = "" Then
Exit Sub
End If
Do While Not rst.NoMatch
intCharPositionFound = InStr([Finding Continued], strText)
If intCharPositionFound > 0 Then
'With txtNotes
With [Finding Continued]
.SetFocus
.SelStart = intCharPositionFound - 1
.SelLength = Len(strText)
End With
End If
MsgBox "Do you want to find more", vbOKCancel, "Highlights"
rst.FindNext "[Finding Continued] like "" * strText * """
Debug.Print strText
Loop
End Sub
Dean J. Waring
Hi,
Do you mean you want to highlight the string in a richText Box? If so, I suggest you try something like below:
Private Sub Command11_Click() 'Declare procedure variables Dim strText As String Dim intCharPositionFound As Integer 'Get text to search for from user strText = InputBox("Enter text to find in Notes field.") If strText = "" Then Exit Sub End If intCharPositionFound = InStr(Me.UserNote, strText) Me.UserNote.SetFocus If intCharPositionFound > 0 Then Me.UserNote.Text = Replace(Me.UserNote.Text, strText, "<strong>" + strText + "</strong>", 1, 1) End If Response = MsgBox("Do you want to find more", vbOKCancel, "Highlights") If Response = vbOK Then ' User chose Yes. Me.UserNote.Text = Replace(Me.UserNote.Text, strText, "<strong>" + strText + "</strong>") End If Debug.Print strText End Sub Private Sub Command12_Click() Me.UserNote.SetFocus Me.UserNote.Text = Replace(Me.UserNote.Text, "<strong>", "") Me.UserNote.Text = Replace(Me.UserNote.Text, "</strong>", "") End SubBest Regards,
Edward
这篇关于Hightling并在Access 2010中的备注字段中查找下一个匹配搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!