在数据表对象中使用 ColumnHidden 属性
我有一个 MS Access 表单,其中包含一个数据表 子表单。
我使用代码更改了各个列的 ColumnHidden 属性。 但是,当我关闭表单时,系统会询问我是否保存数据表表格的表格布局。
- 如何阻止表单不断要求用户相同的表格布局?
- 我是否别无选择,只能将数据表更改为常规子表单?
I have a MS Access form with a Datasheet subform.
Using code, I change the ColumnHidden property of various of its columns.
But, when I close the form, I'm asked whether to save the table layout of the Datasheet's table.
- How can I stop the form from asking the user to same the table layout continually?
- Do I have no choice but to change the Datasheet to a regular subform?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您始终隐藏相同的列 - 创建一个仅包含您想要显示的列的查询,并将其用作子表单的源。
如果您仍然需要一些隐藏字段(子键等),您将必须创建一个常规表单。 这还不错:
If you are always hiding the same columns - create a query that only has the columns you want displayed and use that as the source of your subform.
If you still need some hidden fields (child keys, etc.) you will have to create a regular form. It's not too bad:
我不确定是否有一种简单的方法可以做到这一点,因为 Access 使用表单保存了大量属性。 如果您没有使用数据表视图,则可以隐藏窗体上的“关闭”按钮,并将其替换为命令按钮,以使用以下代码关闭窗体:
但由于它是数据表,因此您不能这样做。
您可能会尝试将数据表作为子窗体嵌入到未绑定的父窗体中,但我不知道在父窗体上的命令按钮后面使用上面的代码是否会将列宽保存到嵌入的子窗体中。
一种解决方案是在数据表的 OnLoad 事件中重新初始化列宽。 然后,您可以使用 acHidden 打开表单,并在 OnLoad 事件中,将列宽设置为正确的值(您需要将英寸乘以 1440 以获得要分配给列宽属性的缇值),然后在OnLoad 结束时,将 Me.Hidden 设置为 False。
但这确实是一件令人痛苦的事情。
恐怕这是使用数据表的缺点之一,因为无法定义不会保存最终用户 UI 数据的关闭命令按钮。
I'm not sure there's an easy way to do this because Access saves a lot of properties with forms. If you were not using Datasheet view, you could hide the CLOSE button on the form and replace it with a command button to close the form with this code:
But since it's a datasheet, you can't do that.
You might try embedding your datasheet as a subform in an unbound parent form, but I don't know if using the code above behind a command button on the parent form will or will not save the column widths to the embedded subform.
One solution would be to re-initialize the column widths in the OnLoad event of your datasheet. You could then open the form with acHidden, and in the OnLoad event, set the column widths to their correct values (you'll want to multiply inches times 1440 to get the twips value to assign to the column width properties), and at the end of the OnLoad, set Me.Hidden to False.
But that is, indeed, something of a pain in the butt.
I'm afraid it's one of the downsides of using datasheets, since there's no way to define a close command button that won't save end-user UI data.