Setting Filter in Subform

谁说胖子不能爱 提交于 2019-12-12 11:03:50

问题


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

Which successfully pulls out the Room_ID from the first Subform.

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.

I cant get

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

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.

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

Edit 2:

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


回答1:


Did you try turning the filter on?

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

Edit:

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



回答2:


Check your spelling of "Properties"...

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


来源:https://stackoverflow.com/questions/21109977/setting-filter-in-subform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!