在子窗体中设置过滤器 [英] Setting Filter in Subform

查看:94
本文介绍了在子窗体中设置过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主窗体"Properties",它具有两个子窗体,其中一个显示该属性中的房间,另一个子窗体显示每个房间中的居住者.

I've a main form "Properties", which has two subforms, one of which displays the rooms in that property, the other one occupants in each room.

更改属性时,房间会在第一个子窗体(连续)中发生变化.当您向下滚动房间子窗体以激活新房间时,我希望占用者在第二个子窗体中进行更改.

As you change the property, the rooms change in the first subform, which is continuous. As you scroll down the room subform, making a new room active, I want the occupants to change in the second subform.

到目前为止,我已经在属性"主表单的当前事件中编写了此代码:

So far I've written this in the Current event of the "properties" main form:

Dim dblRoomID As Double
dblRoomID = Forms.Properties.frmRoomsByPropertySubform.Form.room_id

成功从第一个子窗体中拉出Room_ID.

Which successfully pulls out the Room_ID from the first Subform.

现在,我需要使用该Room_ID在第二个子窗体中设置一个过滤器,该窗体当前显示所有属性的所有占用者,但是具有Room_ID字段.

Now I need to use that Room_ID to set a filter in the second subform, which currently displays all occupants of all properties, but has a Room_ID field.

我不能得到

Forms.Properies.frmStudentsRoomQuickview.Form.Filter = "[Room_ID]=" & dblRoomID

或docmd.applyfilter可以工作-我一直在假设这是因为活动表单需要是'frmstudentRoomQuickview'才能稍后工作-但我不明白为什么简单地设置.filter将无法正常工作.

or docmd.applyfilter to work - I've been working on the assumption that this is because the active form needs to be the 'frmstudentRoomQuickview' for the later to work - but I can't understand why simply setting the .filter won't work.

我要补充一点,因为房间"表单需要是连续的,所以我不能在房间"表单中使用子表单.

I should add, I can't use a subform within the "rooms" form, as the rooms form needs to be continuous.

Private Sub Form_Current()
Dim dblRoomID As Double
    If IsNull(Forms.Properties.frmRoomsByPropertySubform.Form.room_id) Then
        Forms.Properties.frmRoomsByPropertySubform.Visible = False
        Forms.Properties.frmStudentsRoomQuickview.Visible = False
    Else
        Forms.Properties.frmRoomsByPropertySubform.Visible = True
        Forms.Properties.frmStudentsRoomQuickview.Visible = True
        dblRoomID = Forms.Properties.frmRoomsByPropertySubform.Form.room_id
        Call frmStudentsRoomQuickview_Enter(dblRoomID)
    End If

End Sub

Private Sub frmStudentsRoomQuickview_Enter(dblRoomID)
Forms.Properties.frmStudentsRoomQuickview.Filter = "[room_id] = " & dblRoomID
Forms.Properties.frmStudentsRoomQuickview.FilterOn = True
Forms.Properties.frmStudentsRoomQuickview.Requery
Debug.Print Screen.ActiveForm.name
End Sub

我现在收到过程声明与具有相同名称的事件或过程的描述不匹配"错误

I'm now getting "Procedure declaration does not match description of event or procedure having same name" errors

推荐答案

您是否尝试打开过滤器?

Did you try turning the filter on?

Forms.Properies.frmStudentsRoomQuickview.Form.Filter = "[Room_ID]=" & dblRoomID
Forms.Properies.frmStudentsRoomQuickview.Form.FilterOn = True

看到您的更新后,我知道了这个问题.问题是您不能将参数传递给_Enter事件.您必须执行以下操作:

Having seen your update, I understand the issue. The problem is that you cannot pass a parameter to the _Enter event. You'd have to do something like this:

Dim dblRoomID As Double

Private Sub Form_Current()

    dblRoomID = 0

    If IsNull(Forms.Properties.frmRoomsByPropertySubform.Form.room_id) Then
        Me.frmRoomsByPropertySubform.Visible = False
        Me.frmStudentsRoomQuickview.Visible = False
    Else
        Me.frmRoomsByPropertySubform.Visible = True
        Me.frmStudentsRoomQuickview.Visible = True
        dblRoomID = Me.frmRoomsByPropertySubform.Form.room_id
        DoStudentsRoomQuickViewFilter
    End If

End Sub

Private Sub DoStudentsRoomQuickViewFilter()
    If dblRoomID <> 0 Then
        Me.frmStudentsRoomQuickview.Form.Filter = "[Room_ID] = " & dblRoomID
        Me.frmStudentsRoomQuickview.Form.FilterOn = True
        Me.frmStudentsRoomQuickview.Requery
        Debug.Print Screen.ActiveForm.Name
    End If
End Sub

Private Sub frmStudentsRoomQuickview_Enter()
    DoStudentsRoomQuickViewFilter
End Sub

这篇关于在子窗体中设置过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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