编程改变RecordsetType在MS Access或更好的方法 [英] Programmatically changing the RecordsetType in ms access or a better method

查看:271
本文介绍了编程改变RecordsetType在MS Access或更好的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MS Access我有一个形式,它也有一个子表单。我想在主形式RecordsetType编程更改到快照时副台/子形式具有相关联的在一对多的关系记录。我写了一些VBA code要做到这一点,但我遇到了一些非常奇怪的行为。

In ms access I have a form which also has a sub-form. I wanted to programmatically change the RecordsetType in the main-form to snapshot when the sub-table/sub-form has associated records in the one-to-many relationship. I wrote some vba code to do this but I was experiencing some very odd behaviour.

我这时才发现,这是因为当我改变RecordsetType,形式刷新和导航回的第一条记录。也就是说然后使在当前事件和相关联的code键火在子表格,主要形式都两次。我在考虑使用DoCmd.SearchForRecord导航回原来的纪录,但很快就意识到,这是行不通的,因为WHERE条件在DoCmd.SearchForRecord当事件触发的第二次左右被覆盖。这一切都显得如此低效的任何方式。

I then discovered that it was because when I change the RecordsetType, the form refreshes and navigates back to the first record. That then causes the On Current event and associated code to fire in both the sub-form and main-form twice. I was thinking of using DoCmd.SearchForRecord to navigate back to the original record but quickly realized that it wouldn't work because the the WHERE condition in the DoCmd.SearchForRecord gets overridden when the events fire the second time around. It all seemed so inefficient any way.

还有没有其他的方法做什么,我想干什么?我真的不希望的形式为禁用设置控件。

Are there any other methods to do what I am trying to do? I don't really want to set the controls in the form to 'Disabled'.

推荐答案

MS Access有一个选择表单属性,应该适合的:AllowEdits,AllowDeletions和AllowAdditions。这些可以单独或混合来设置。在这种情况下,似乎需要AllowAddition设置为是,并AllowEdits设置为否。

MS Access has a selection of form properties that should suit: AllowEdits, AllowDeletions and AllowAdditions. These can be set separately or together. In this case, it seems that you need AllowAddition set to Yes and AllowEdits set to No.

这篇关于编程改变RecordsetType在MS Access或更好的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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