如何将文本字段转换在Access表使用VBA富文本备忘录 [英] How to convert a text field in an Access table to a rich text memo using VBA

查看:259
本文介绍了如何将文本字段转换在Access表使用VBA富文本备忘录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用户有一些后端.ACCDB数据库(我不能直接访问)。我需要code一些VBA修改一些表中这些数据库的结构,文本字段转换为富文本备忘录。 (字段已经包含文本,包括访问富文本,即相关的HTML代码)。

My users have a number of backend .accdb databases (which I can't access directly). I need to code some vba to modify the structure of some of the tables in these databases to convert Text Fields to Rich Text memos. (The fields already contain text including Access "rich-text" i.e. the relevant html coding).

我需要:

  1. 修改字段是一个丰富的文本提示。
  2. 修改现有内容(如适用),以作为形式,数据表和报告,访问丰富的文本正确显示。

我可以写一个SQL语句将修改字段从TEXT(255),以备注:

I can write a SQl statement that will modify a field from TEXT (255) to MEMO:

ALTER TABLE tblSource ALTER COLUMN Detail1 MEMO

不过,这叶产生的备注字段作为一个纯文本备忘录。

However, this leaves the resultant memo field as a plain text memo.

我已经考虑创建一个新的富文本字段,然后复制的旧的内容(使用SQL CREATE TABLE语句后面适用明文功能的老字段的内容,然后将结果复制UPDATE语句到新的领域,然后再SQL来删除旧的领域,并重新命名新的),但不能找出如何创建一个富文本提示(默认好像是纯文本)。

I have considered creating a new Rich Text Field and then copying the contents of the old one (using a SQL CREATE TABLE statement followed by an UPDATE statement that applies the Plaintext function to the contents of the old field and then copies the result to the new field, and then further SQl to delete the old field and rename the new) but can't find out how to create a rich-text memo (default seems to be plain text).

广泛的网络搜索还没有表现出任何额外的技术,我可以部署。这是将要为每个文件运行一次的过程,所以它并不需要是高雅还是很快,但它确实需要防弹!

Extensive web searches haven't shown up any additional techniques I can deploy. This is a process that will be run once for each file, so it doesn't need to be elegant or quick but it does need to be bomb-proof!

推荐答案

由于格式文本的不是数据类型,是不是可以定义或修改一个SQL语句字段属性,你会需要VBA来设置字段的的TextFormat 的属性。

Since Rich Text is not a datatype and is not a field property which can be defined or modified with a SQL statement, you will need VBA to set the field's TextFormat property.

您可以从这个code样品适应技术。

You can adapt techniques from this code sample.

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set db = CurrentDb
Set tdf = db.TableDefs("Table1")
Set fld = tdf.Fields("memo_fld")
Debug.Print "acTextFormatPlain: " & acTextFormatPlain & _
    "; acTextFormatHTMLRichText: " & acTextFormatHTMLRichText
With fld.Properties("TextFormat")
    Debug.Print "TextFormat: " & .Value
    If .Value = acTextFormatPlain Then
        .Value = acTextFormatHTMLRichText
        Debug.Print "TextFormat changed to: " & .Value
    End If
End With

注意:code都包含目标表的数据库上运行。如果表1 实际上是链接到一个表中的另一个Access数据库文件时,code会失败。

Note that code is run from the database which contains the target table. If Table1 was actually a link to a table in another Access db file, the code would fail.

请注意也只适用于一个备注字段。在的TextFormat 的属性不是普通的文本数据类型字段创建的,因此这将引发错误#3270,属性未找到。

Note also that only applies to a memo field. The TextFormat property is not created for regular text datatype fields, so this will throw error #3270, "Property not found."

Debug.Print tdf.Fields("some_text").Properties("TextFormat").Value

<打击>由于您将定期转换文本字段备注字段,这点可能不是一个问题。我提到它只是如果你跌倒了进去。

Col​​eValleyGirl发现的的TextFormat 的属性并不总是一个新的备注字段创建的。

ColeValleyGirl discovered the TextFormat property is not always created for a new memo field.

这篇关于如何将文本字段转换在Access表使用VBA富文本备忘录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆