访问报告字段截断为 255 个字符 [英] Access report field truncating at 255 characters

查看:55
本文介绍了访问报告字段截断为 255 个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个报告,其记录源是一个查询,比如 qryRecords.在报告标题中,我想添加一个冗长的注释字段(超过 255 个字符).我已经建立了一个表格来保存这些笔记(字段类型为备忘录"),并且由于该表格与报告的记录源是分开的,我将使用 VBA 代码将 Notes 字段放入报告中.

I have a report whose record source is a query, say qryRecords. In the report header I want to add a lengthy notes field (longer than 255 characters). I have set up a table to hold these notes (with a field type "memo"), and because that table is separate from the record source for the report, I was going to put the Notes field in the report using VBA code.

在报表的打开事件中,我添加了这段代码:

In the open event of the report, I have added this code:

Dim rst as Recordset
Dim sql_qry as String

sql_qry = "SELECT notes FROM tblNotes WHERE id = 1;"
Set rst = CurrentDb.OpenRecordset(sql_qry)

rst.MoveFirst
Me.txtNote = rst![notes]  'I get the run-time error on this line

不幸的是,我收到一个运行时错误(您无法为该对象分配值").我在表单上发现了一个有类似问题的人,建议将代码从 open 事件移动到 OnCurrent 事件,但报告中不存在该事件.有什么建议么?谢谢.

Unfortunately I get a run-time error where noted ("You can't assign a value to this object"). I found a person with a similar issue on a form, and the suggestion was to move the code from the open event to the OnCurrent event, but that event doesn't exist for a report. Any suggestions? Thanks.

---原始问题---

我有一个带有未绑定文本框 (txtNotes) 的表单,当用户打开该表单时,该文本框填充了长度超过 255 个字符的文本(它连接了数据库中的各个字段).这没有问题.

I have a form with an unbound text box (txtNotes), and when the user opens the form, the text box is populated with text that is longer than 255 characters (it concatenates various fields from the database). This works with no problem.

窗体上有个按钮打开报表,在报表中,我把一个文本框的Control Source设置为Forms![frmMain]![frmSub]![txtNotes],也就是上面提到的文本框.这也有效,但由于某种原因,报告中的文本被截断为 255 个字符.表单的文本框未绑定,因此没有基础表来限制长度.有谁知道为什么会发生这种情况,或者是否有解决方法?

There's a button on the form that opens a report, and in the report, I set the Control Source for a text box to Forms![frmMain]![frmSub]![txtNotes], which is the text box mentioned above. That works too, but for some reason the text on the report is truncated at 255 characters. The form's text box is unbound, so there's no underlying table to limit the length. Does anybody know why this would happen or if there's a workaround?

推荐答案

最有可能是当字段中的数据被转换为文本类型而不是备忘录时.真的没有办法明确地将文本转换为备忘录(尽管使用 CStr,您可以反过来).在尝试这种情况时,我也遇到了表单截断的问题.

Most likely when the data from the field is being cast as a Text type rather than as a Memo. Really there's no way to explicitly cast a Text as a Memo (you can go the other way around though with CStr). I had problems with truncation on the form as well when experimenting with this scenario.

我建议您可能以错误的方式在表单上生成此字段.美元到甜甜圈,您可以在查询中生成它(在表单的控件源中使用),而不是将它连接在一起并放入未绑定的字段中.同样,您可以使用相同的查询作为您打开的报表的控件源.

I'd suggest you are probably generating this field on the form in the wrong way. Dollars to doughnuts you could generate it in a query (used in the form's Control Source), rather than concatenating it together and placing into an unbound field. Likewise, you could then use that same query as the control source for the report that you are opening.

如果这一切真的不可能,我会建议您将表单中的值转储到专门用于报告的表格中,然后将该表格用作报告的控制源.

If all of that is truly impossible, I'd point you at dumping the values from the form into a table specifically for the report and then using the table as a control source for the report.

---- 编辑----

---- Edit ----

我仍然认为您可以将其添加到报告的数据源中.在下面的示例中,我将 tblNotes 附加到 Bar 表上的一个选择.

I still contend that you can add it to your Report's data source. In my example below, I've tacked on tblNotes to a select on the Bar table.

SELECT bar.f0, bar.f1, bar.f2, bar.f3, tblNotes.notes 
FROM bar, tblNotes 
WHERE tblNotes.id = 1;

是的,如果有 300 行 Bar,您将获得 300 个相同 Notes 字段的副本,但这是一个小问题.

Yes, if there is 300 rows of Bar, you'll get 300 copies of the same Notes field, but that's a minor problem.

在那里形成表格,您只需将 txtNote 的数据源设为 tblNotes.Notes 列.txtNote 肯定可以存在于报表/页眉中,MS Access 生成它时,它只会使用一行.我不确定是选择第一行/最后一行还是随机行 - 因为它们都是相同的,所以不会更少.

Form there, you just make txtNote's data source the tblNotes.Notes column. txtNote can certainly exist in the report/page header, and when MS Access generates it, it will only use one row. I'm not sure if picks the first/last row, or random row - never the less since they are all the same, it doesn't matter.

这篇关于访问报告字段截断为 255 个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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