简体   繁体   English

MS Access(2010)VBA筛选器不适用于一个子窗体

[英]MS Access (2010) VBA filter not working on one subform

I have been struggling to identify the source of this problem for the past few days. 在过去的几天里,我一直在努力寻找问题的根源。 My Internet searches for what's causing this issue have not been fruitful. 我的Internet搜索导致此问题的原因并没有取得成功。

This is a program uses Access as the front end UI for user to enter client information into the database hosted on SQL Server. 该程序使用Access作为前端UI,以便用户将客户端信息输入到SQL Server上托管的数据库中。

The interaction should be as follows: 交互作用应如下所示:

  • User click on client list in main form 用户单击主要形式的客户清单
  • A list of accounts is displayed in main form 帐户清单以主要形式显示
  • User click on an account 用户点击一个账户
  • List of products is displayed in a tabular subform (for update/add new product) 产品列表以表格子形式显示(用于更新/添加新产品)
  • User select one of the products 用户选择其中一种产品
  • Corresponding monthly product values are displayed on another subform (not under the products list subform) 相应的每月产品值显示在另一个子窗体上(不在“产品列表”子窗体下)

When the main form is initially loaded, the monthly product values filter value is 0 by default. 最初加载主表单时,默认情况下每月产品值过滤器值为0。 The filter should be updated dynamically when one of the products is selected. 选择其中一种产品时,应动态更新过滤器。 It was done under the Form_Current event for the products form. 这是在产品表单的Form_Current事件下完成的。

What I can't figure out is: The filter seems to stuck at the default state. 我不知道的是:筛选器似乎卡在默认状态。 I used the Debug.Print statement to check the latest filter value for the monthly product values form and it shows the correct product ID for the filter. 我使用Debug.Print语句检查了每月产品价值表单的最新过滤器值,它显示了该过滤器的正确产品ID。 But it's not updated on the UI at all. 但是它根本没有在用户界面上更新。

What's even weirder is: it works (ie monthly values are listed) sometime when I made changes to the vba code (that sometimes not related to filter) and save it when it's in Application mode eg: 更奇怪的是:它在我更改了vba代码(有时与过滤器无关)的某个时候起作用(即列出了每月值),并在处于应用程序模式时保存了它,例如:

.filter = "prod_id = " & iProdID

to

.filter = "[prod_id] = " & iProdID

But then when I change it to Design mode and start making changes not related to this issue, it stopped working when it's in Application mode again. 但是,当我将其更改为“设计”模式并开始进行与此问题无关的更改时,当它再次处于“应用程序”模式时,它停止工作。 The behavior is so unpredictable that I am not sure how to proceed. 行为是如此不可预测,以至于我不确定如何进行。 I even remove the form and recreate it again and it's still behaving similarly. 我什至删除了表单,然后再次重新创建它,其行为依旧相似。

I am using the same way to work on the filer in VBA for the other subforms and they are behaving correctly. 我使用相同的方法在VBA中处理其他子表单的文件管理器,并且它们的行为正确。 Hope to get some feedback on what I overlooked! 希望得到一些我忽略的反馈!

Thanks! 谢谢! Kiat at

I got it to work now. 我现在开始工作了。 The original method to assign filter for the product values was to assign the filter value directly to the Product Values form ( Form_ProductVals ) from the Products form's ( Form_Products ) Form_Current event. 为产品值分配过滤器的原始方法是,将过滤器值直接从“产品”表单( Form_Products )的Form_Current事件分配给“产品值”表单( Form_ProductVals )。 That was causing the inconsistency in the results. 这导致结果不一致。

Now I changed the code to assign the filter value through the main Clients form (that contains Products and ProductVals subforms). 现在,我更改了代码,以通过“客户”主窗体(包含“产品”和“ ProductVals”子窗体)分配过滤器值。 So the code was changed from: 因此代码从以下更改:

Form_ProductVals.Form.Filter = "prod_id = " & <new ID>

to

Form_Clients.ProductVals.Form.Filter = "prod_id = " & <new ID>

That does the trick. 这样就可以了。 I don't have an explanation of the difference though. 不过,我没有任何区别的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM