首页 > 解决方案 > 如何以连续形式操作单个记录

问题描述

我有一个子表单,它是一个连续表单,它列出了父表单中每条记录的文本元素。在这种情况下,父表单列出了特定的索赔编号,而子表单提供了该索赔的文本元素。我在网上找到了一些巧妙的代码,它使用文本元素顶部的未绑定文本框来重现声明文本,但突出显示了一个选定的单词。特定单词来自相关的单词列表。但有时,索赔中的单词与此列表中的单词并不完全相同。例如,列表中的单词可能是“run”,但我也想突出显示“running”或“runs”。我已经探索了各种方法来识别不同的变体,例如在文本中找到“运行”,然后使用 InStr() 和 Mid() 等找到单词的其余部分。这很有效,一般来说,但仅限于第一个记录。尽管基本过程适用于连续形式的所有记录,但我无法弄清楚如何以编程方式查看每个单独记录的文本以评估我需要搜索的内容。我尝试了一些 RecordSet 循环,但它似乎总是只看第一条记录。

查看其他一些帖子,我觉得这可能是不可能的,但希望有任何见解。下面的代码有效。只是想弄清楚如何调整它,以便我可以处理单个记录中的文本并突出显示单词的变体。

谢谢。

Public Sub Form_Current()
Dim ctl As Control
On Error GoTo Err_Handler

    'Purpose:   Highlight matches in txtSearchDisplay.
    Dim strField As String              'The field to search
    Dim strSearchValue As String        'The value to find
    Dim strControlSource As String      'ControlSource for displaying match.
    Const strcWildcard = "*"            'Some other back ends use %
    'HTML tags for highlighting matches. Could be just "<b>" and "</b>".
    Const strcTagStart = "<font color=""""red"""">"
    Const strcTagEnd = "</font>"


  'Search for claim term value in claim element text.
   strField = "ClaimElementText" 'Field containing claim text
   strSearchValue = Forms![frmWords].ClaimTerm  'This is the word to highlight
   'Control Source for the text box to display matches.

      strControlSource = "=IIf(" & strField & " Is Null, Null, " & _
         "Replace(" & strField & ", """ & strSearchValue & """, """ & _
         strcTagStart & strSearchValue & strcTagEnd & """))"

   With Forms![frmWords]![sbfmClaims].Form![sbfrmClaimText].Form!txtSearchDisplay
      .ControlSource = strControlSource
      .Visible = True
      .BackColor = RGB(255, 255, 255)
   End With

   'This is necessary to get the term highlighting to show up on first limitation.
   Forms![frmWords]![sbfmClaims].Form![sbfrmClaimText].Form!txtSearchDisplay.SetFocus

Exit_Handler:
    Exit Sub

Err_Handler:
    Resume Exit_Handler

End Sub

标签: ms-accesscontinuous-forms

解决方案


推荐阅读