ms-access - 无法在 Report_Open 中更改文本框的文本

标签 ms-access vba textbox label report

我想要做的就是在通过单击另一种形式的按钮打开报表时将文本框或标签的文本设置为动态的内容。除了实际更改文本之外,我已经解决了所有问题。

此代码在 SetFocus 上给出了运行时错误 2478:

Me.tFilial.SetFocus
Me.tFilial.Text = filialen

如果没有 SetFocus,我会收到一个运行时错误,指出如果不将控件切换到相关控件,就无法更改文本。

在 Access 中似乎总是有问题的地方允许什么。我该如何解决这个问题?我可以使用

以其他形式设置按钮点击上的值吗
Reports![rptPressSchema]![tFilial].text="Hello"?

如果可以解决问题,我很乐意改用标签。但最重要的是,我可以尝试以各种方式做到这一点,但我想我会就最佳实践向您征求意见,因为这确实是一项非常常见的任务。

最佳答案

来自 Access 帮助:

While the control has the focus, the Text property contains the text data currently in the control; the Value property contains the last saved data for the control. When you move the focus to another control, the control's data is updated, and the Value property is set to this new value. The Text property setting is then unavailable until the control gets the focus again. If you use the Save Record command on the Records menu to save the data in the control without moving the focus, the Text property and Value property settings will be the same.

基本上,.Text 属性在报表中没有任何作用,因为单个控件无法获得焦点。但是,正如@Remou 在他的评论中所述,您可以简单地将 .Text 替换为 .Value 并且您的代码应该可以正常工作(更新值时无需设置焦点) .

关于ms-access - 无法在 Report_Open 中更改文本框的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8614268/

相关文章:

ms-access - 使用 vba 将 MS Access 查询输出到 Excel

sql-server - MS Access 使用 Windows 用户名连接到 SQL Server

vba - 使用 Excel VBA 执行字符替换

c# - WPF C# 拖放

mysql - Access 和MySQL

php - php 中的数据库连接与 linux 主机上的 MS Access

mysql - 将记录从在线 MySQL 数据库导入到 MS Access 数据库

excel - 如何在需要时使用 VBA 将 Excel 中单元格的值保持为限制和循环?

c# - 锁定文本框中的有效字符

javascript - 文本框聚焦