Access 2007 拆分表单 VBA:打开时的 acNewRec 阻止通过表单进行 Tab 键切换 - 就像第一个字段未“选择”一样;
我希望有人可以帮助我,或者至少帮助我找出解决方法。
我正在使用 Access 2007 的分割表单功能,并在 Form_Open 事件以及两个 button_click 事件之后运行下面的代码。该代码在 button_click 事件之后运行时工作正常,但是当它在 form_open 事件上运行时,会导致问题。
如果打开表单并且用户在第一个字段中输入文本,则他/她无法使用 Tab 或鼠标选择下一个表单字段。用户会停留在第一个表单字段上,直到按 Esc 键取消数据输入。为了在打开表单时在第一个表单字段中成功输入数据,用户必须首先选择另一个表单字段,然后重新选择第一个表单字段,然后在第一个表单字段中输入文本。在这些废话之后,用户可以使用 Tab 或鼠标选择下一个表单字段。每次启动表单时都必须执行一次。 Button_click 事件上的相同 VBA 代码工作正常。
值得注意的是:首次打开表单时,表单数据表部分中的任何表单字段都不会显示“已选定”。当用户开始在第一个表单字段中输入数据时,“新记录”标记 (*) 会按其应有的方式移动到第二行,但第一行不会显示正在输入的数据。这种行为很奇怪。
执行清除字段后,单击另一个字段,单击返回到上述第一个字段解决方法,数据表显示正确选择的字段和输入的数据。
有什么想法吗?这是一个错误吗?是否有简单的解决方法,例如在表单打开时通过 VBA 执行字段选择解决方法?
非常感谢任何帮助。
代码:
DoCmd.ApplyFilter , "([Contractor].[CheckOutStamp] Is Null)"
DoCmd.GoToRecord , "", acNewRec
I hope someone can help me out, or at least help figure out a workaround.
I'm using Access 2007's split form feature, and have the code below run on the Form_Open event, as well as after two button_click events. The code works fine when run after the button_click events, but when it runs on the form_open event, it causes problems.
If form is opened and user enters text in the first field, he/she cannot use Tab or mouse to select the next form field. The user is stuck on the first form field until pressing Esc to cancel the data entry. In order to successfully enter data in the first form field when the form is opened, a user must first select another form field, then re-select the first form field then enter text in first form field. After this nonsense, the user CAN select next form field with Tab or mouse. This must be performed once every time the form is launched. The same VBA code on the button_click events works fine.
Noteworthy: When the form is first opened, NONE of the form fields in the datasheet section of the form appear 'Selected'. When a user begins to enter data in the first form field, the 'new record' marker (*) moves to the second row as it should, but the first row does not show the data being input. This behavior is odd.
After performing the clear field, click another field, click back to first field workaround described above, the datasheet shows properly selected fields and Data as it is input.
Any ideas? Is this a bug? Is there an easy workaround, such as performing the field-select workaround via VBA at form open?
Any help is MUCH appreciated.
Code:
DoCmd.ApplyFilter , "([Contractor].[CheckOutStamp] Is Null)"
DoCmd.GoToRecord , "", acNewRec
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些想法:
尝试将其从 OnOpen 移至 OnLoad。 OnOpen 中的事件可以在数据实际加载之前发生,而 OnLoad 则在数据完成之后发生。
另外,您可能只想将表单的 Filter 属性设置为
[Contractor].[CheckOutStamp] Is Null
并将 FilterOn 设置为 Yes,并将表单设置为 DataEntry,这意味着它默认为新的打开时记录,并且不加载任何旧记录。打开后,您可以将表单的编辑/添加模式更改为您喜欢的任何模式。Some thoughts:
Try moving it from OnOpen to OnLoad. The events in OnOpen can happen before the data is actually loaded, where as OnLoad happens after that is already done.
Also, you might want to just set the form's Filter property to
[Contractor].[CheckOutStamp] Is Null
and set the FilterOn to Yes, and set the form to DataEntry, which means it defaults to a new record upon open, and doesn't load any of the older records. Once it's open, you can change the form's edit/add mode to whatever you like.