MS Access表格中的下划线文本

时间:2018-01-29 18:29:43

标签: ms-access-2013

我在MS ACCESS的表格中有很长的文本字段。我需要在字段中为特定文本加下划线。我试图在设计视图中将文本格式更改为Rich Text,但我得到了:

  

错误:此类对象

不支持操作

在表格中我有320行。我需要为N.J.S.A强调只在长篇文章中。

请帮我解决这个问题。在此先感谢

1 个答案:

答案 0 :(得分:1)

嗯......您必须将该字段属性从纯文本更改为富文本才能使其工作,并且设计视图应该处理此问题。如果没有尝试下面的代码。

Public Sub TestUnderline()
Dim db                              As DAO.Database
Dim tbl                             As DAO.TableDef
Dim fld                             As Field
Dim rst                             As DAO.Recordset
Dim strSQL                          As String
Dim strString                       As String

Set db = CurrentDb
Set tbl = db.TableDefs("Table1") 'Change to your table name
Set fld = tbl.Fields("TestField") 'Change to your field name

With fld.Properties("TextFormat")
    If .Value = acTextFormatPlain Then
        .Value = acTextFormatHTMLRichText
    End If
End With

strSQL = "SELECT TestField " & _ 'Change to your Field name
         "FROM Table1;" 'Change to your table name
Set rst = db.OpenRecordset(strSQL)

Do While Not rst.EOF
    If InStr(1, rst![TestField], "N.J.S.A") Then 'Change to your field name
        strString = Replace(rst![TestField], "N.J.S.A", "<u>N.J.S.A</u>") 'Change to your field name
        rst.Edit
        rst![TestField] = strString 'Change to your field name
        rst.Update
    End If
    rst.MoveNext
Loop


EndCode:
If Not rst Is Nothing Then
    rst.Close
    Set rst = Nothing
End If
If Not tbl Is Nothing Then
    Set tbl = Nothing
End If
If Not db Is Nothing Then
    Set db = Nothing
End If
End Sub

信用给予: How to convert a text field in an Access table to a rich text memo using VBA

和: http://www.tek-tips.com/viewthread.cfm?qid=1538917