简体   繁体   English

使用VBA筛选MS Access子表单

[英]Filtering MS Access subform with vba

I have a quick question. 我有一个快速的问题。 I've developed a booking system that has a sub form containing all the rooms booked on the date displayed (in main form). 我已经开发了一个预订系统,该系统具有一个子窗体,该子窗体包含在显示日期(主窗体)上所有已预订的房间。 I've added a combo box to allow users to filter the rooms to only see the ones they select from combo box (re-query the sub-form and then filter). 我添加了一个组合框,以允许用户筛选房间以仅查看他们从组合框中选择的房间(重新查询子窗体,然后进行筛选)。

This works fine apart from the fact my code would sometimes loop through the filtering sub for no apparent reason after reaching the end of the sub?. 除了我的代码有时在到达子末尾后,没有明显的原因有时会循环通过过滤子的情况之外,这种方法还不错。 It displays everything correctly, so this I'm not bothered about (unless it's connected to the real problem). 它可以正确显示所有内容,所以我对此并不感到困扰(除非它与实际问题有关)。

The real problem I'm having however is when I choose a room that has no bookings for the date displayed. 但是,真正的问题是,当我选择的房间没有显示日期的预订时。 The filter works fine (empty display), but when I then try to choose another room from the combo box the re-query function behind the after update of the combo box does not work! 筛选器工作正常(空显示),但是当我尝试从组合框选择另一个房间时,组合框更新后的重新查询功能不起作用!

Has anyone else experienced this before? 之前有没有其他人经历过?

The workflow: 工作流程:

Combo box triggers 'after update' event. 组合框触发“更新后”事件。 This re-queries the sub-form, where behind the 'on current' event the filtering of the sub-form happens. 这将重新查询子表单,在“当前”事件之后,将对子表单进行过滤。

When sub-form is empty I'm unable to perform any further sub-form re-queries. 当子表单为空时,我将无法再执行任何子表单重新查询。

I do something similar and had a hard time with this but was able to fix it with the following code in my combo_box_afterupdate event. 我做了类似的事情,对此很费劲,但是能够通过我的combo_box_afterupdate事件中的以下代码修复它。

Dim rs As Object
Me.Form.Filter = ""
Me.Form.Refresh
Set rs = Me.Recordset.Clone
rs.FindFirst "[ValueToFind] = '" & Me![MyComboBoxValue] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Also be sure to link parent and child as last person mentioned. 还要确保链接父母和孩子为最后提到的人。

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

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