MS Access 将类似函数转换为备忘录数据类型
我需要对 MS Access 中的报表中的字段使用富文本格式,以便使用字符间距。在报告中,尝试将字段属性中的文本格式从纯文本更改为富文本会产生错误:“您输入的设置对此属性无效。”我认为这是因为该字段不是备忘录数据类型(显然是唯一支持 RTF 的数据类型)。它的格式为“XXXX_XXXX”,其中 * 和 _ 是文字字符,X 代表数字 0 到 9。
对于上下文:该数据库的工作流程是,它具有单一形式,当指定id,查询链接表,根据查询结果生成报告,输出为PDF。
该字段的控制源是查询结果中的字段。
一切正常,但我需要能够将此字段设置为 RTF。如果有什么区别的话,该字体是 TrueType 字体。本质上,我想在场地上有一个固定的高度,并在宽度上水平拉伸它。即在 CSS 中,它大致定义为“max-height: 30px; width: 100%;”
我尝试过的事情:
在查询设计视图中,将字段的文本格式设置为富文本。在报表设计视图中设置字段的文本格式时,我仍然收到错误。
另一个想法是将字段显式转换为 Memo 数据类型(任何超过 255 的数据都会隐式转换为这种类型),但我不确定如何在 SQl 中执行此操作 [MS SQL Server 我们将使用类似 CONVERT([fieldname] 的东西, text)]
创建自定义格式会有帮助吗?我想不会,因为它仍然是明文。
预先感谢您的任何帮助和评论。
I need to use rich text formatting for a field in a report in MS Access in order to use character spacing. In the report, attempting to change the Text Format in the field's properties from Plain Text to Rich Text Produces the error: "The setting you entered isn't valid for this property." I presume that is because the field is not a memo data type, (apparently the only data type which supports RTF). It is in the format "XXXX_XXXX" where * and _ are literal characters and the X's represent numbers 0 through 9.
For context: The workflow of this DB is that it has a single form that when specifying an Id, queries a linked table, generates a report based on the query result, and outputs it to PDF.
The field's control source is a field from the query result.
Everything works fine but I need to be able to set this field to RTF. The font is a TrueType font if that makes any difference. Essentially I want to have a fixed height on the field and stretch it horizontally across the width. i.e. in CSS it would be defined roughly as "max-height: 30px; width: 100%;"
Things that I have tried:
In the Query Design View, setting the field's Text Format to Rich Text. I still receive an error when setting the field's Text Format in the Report Design View.
Other idea is to explicitly convert field to the Memo data type (anything over 255 implicitly gets converted to this type), but I am not sure of how to do that in SQl [MS SQL Server we would use something like CONVERT([fieldname], text)]
Would creating a custom format help? I'd imagine not because it would still be plaintext.
Thanks in advance for any help and comments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
除非基础列是富文本列(备注),否则无法将 BOUND 文本框更改为富文本。然而,一个简单的解决方法是在报告上放置一个未绑定的文本框。只需在属性表中将文本设置为富文本(同样,无需使用代码来尝试更改此值)。将文本框放置在表单上后,在为每条记录触发的表单“detail-format”中,您可以在代码中执行:
因此,您可以从上述代码中的其他列中提取值,但请记住对于报告,必须有相应的绑定控件来引用任何列,而表单则没有此要求
You can’t change a BOUND text box to rich text unless the underlying column is a rich text column (memo). However, a simple workaround is place an un-bound text box on the report. Simply set the text to rich text in the property sheet (again, there is no need to use code to try and change this value). Once you have the text box placed on the form, then in the forms “detail-format” which fires for each record, you can in code go:
So, you can pull values from other columns in the above code, but keep in mind for reports there must be a corresponding bound control to reference any column, where as a form does not have this requirement
只是为了解决您建议的想法之一:
遗憾的是,Access 数据库引擎不支持标准 SQL 的
CAST()
函数 :(因为 Access 数据库引擎与 VBA5 库共享表达式服务(为什么不支持 VBA6) ? - 谁知道?!),它可以使用大多数 VBA 转换函数,但遗憾的是数据类型之间的映射不好,唯一相关的函数是
CStr()
(转换为String),但如何将其结果强制转换为各种 Access 数据库引擎文本数据类型(可变长度
VARCHAR
、固定长度CHAR
,带或不带 Unicode 压缩和MEMO
),遗憾的是没有记录。有一个例外:Access 数据库引擎有自己的
CDEC()
(转换为DECIMAL
)函数。但遗憾的是它一直完全损坏。Just to address one of your suggested ideas:
Sadly, the Access Database Engine does not support Standard SQL's
CAST()
function :(Because the Access Database Engine shares an expression service with the VBA5 library (why not VBA6? -- who knows?!), it can use most of the VBA cast functions, however sadly the mapping between data types is not good. The only relevant function is
CStr()
(cast toString
) but how its result are coerced to the various Access Database Engine text data types (variable lengthVARCHAR
, fixed lengthCHAR
, with or without Unicode compression, andMEMO
) sadly is undocumented.There is one exception: the Access Database Engine has its own
CDEC()
(cast toDECIMAL
) function but sadly it has always been completely broken.您将无法直接使用绑定控件执行此操作,除非将其定义为 Memo/Long Varchar 字段。如果情况并非如此,这里有一个解决方法:
确保具有富文本格式的绑定控件(例如 BoundControlX)位于报表中。将文本格式保留为纯文本。 (通常绑定控件也会被设置为不可见。)
创建一个未绑定控件,例如UnboundControlY。使其可见并将文本格式设置为富文本。
将未绑定控件的 Control Source 属性设置为:=[BoundControlX]
有关详细信息,请参阅:https://support.microsoft.com/en-us/office/create-or-delete-a-rich-text-字段-9f86237d-dbbc-4a85-b12c-9d8dca824630
You won't be able to do this directly with a bound control unless it is defined as a Memo/Long Varchar field. If that is not the case, here is a workaround:
Make sure the bound control, e.g. BoundControlX, that has the rich text formatting is in the report. Leave the text format as plain. (Normally the bound control would also be set to not visible.)
Create an unbound control, e.g. UnboundControlY. Make it visible and set the text format to Rich Text.
Set the Control Source property of the unbound control to: =[BoundControlX]
For more details see: https://support.microsoft.com/en-us/office/create-or-delete-a-rich-text-field-9f86237d-dbbc-4a85-b12c-9d8dca824630
尝试将文本字段设置为表中的最后一个字段。我似乎记得某个地方每个表只能有一个备注字段,并且该备注字段必须是最后一个字段。
Try making the text field the last field in the table. I seem to recall somewhere that you can only have one memo field per table and that memo field must be the last field.