【问题标题】:MS Access underline text in a Table表格中的 MS Access 下划线文本
【发布时间】:2018-01-29 18:29:42
【问题描述】:

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

错误:此类对象不支持操作

在表中我有 320 行。我需要在 N.J.S.A 下划线。仅在长文本中。

请帮助我解决这个问题。提前致谢

【问题讨论】:

    标签: ms-access-2013


    【解决方案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

    【讨论】:

    • 克里斯,非常感谢您的快速回复。
    • 嗨,克里斯,非常感谢您的快速帮助我尝试了代码,但在 pdf 输出中显示为 N.J.S.A.。代码中没有错误。
    • 代码只能在 N.J.S.A 下划线。在你的桌子上......没有关于pdf输出的内容。你想用 pdf 输出做什么?
    • 基于表我正在生成报告,该报告输出到 pdf 文档。该代码帮助我在表格中的文本下划线。相同的内容无法正常输出。
    • DoCmd.OutputTo acOutputTable, "YourTableName", acFormatPDF, "Your file location\TestFile.pdf"
    猜你喜欢
    • 2013-08-22
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 2014-08-01
    • 1970-01-01
    • 2015-08-23
    • 2011-02-07
    • 2012-10-18
    相关资源
    最近更新 更多