【问题标题】:Apply searching creteria to subform .Filter property from another form将搜索条件应用于另一个表单的子表单 .Filter 属性
【发布时间】:2017-05-21 21:38:51
【问题描述】:

基本上,我有一个表单MENU,它有一个子表单Tabella1
我想要做的是在Tabella1 的4 个不同字段上运行的搜索查询。

查询确实有效,但不是更新MENU 中的子表单,而是打开一个包含搜索结果的新数据表。

编辑
好的,现在我遵循@June7 的建议,特别是我使用了this guide,基本上我删除了之前的查询。
现在的问题是,一切正常,除了在执行cmdFiltra_Click() -for the button CERCA- 之后,它什么也没有显示。
另外,如果我使用日期标准,而不是其他 4 个标准,它会显示所有记录,尽管在表单底部会出现“已过滤”消息。

这是重新改编的代码-针对我的情况-,格式为Cerca

Private Sub cmdFiltra_Click()

Dim strWhere As String                  
Dim lngLen As Long                      
Const conJetDate = "\#mm\/dd\/yyyy\#"   

If Not IsNull(Me.regioneRicerca) Then
    strWhere = strWhere & "([Forms]![MENU]![Tabella1].[Form].[REGIONE SOCIALE] Like ""*" & Me.regioneRicerca & "*"") AND "
End If

If Not IsNull(Me.localitaRicerca) Then
    strWhere = strWhere & "([Forms]![MENU]![Tabella1].[Form].[LOCALITA] Like ""*" & Me.localitaRicerca & "*"") AND "
End If

If Not IsNull(Me.fiscaleRicerca) Then
    strWhere = strWhere & "([Forms]![MENU]![Tabella1].[Form].[CODICE FISCALE] Like ""*" & Me.fiscaleRicerca & "*"") AND "
End If


If Not IsNull(Me.stallaRicerca) Then
    strWhere = strWhere & "([Forms]![MENU]![Tabella1].[Form].[CODICE STALLA] Like ""*" & Me.stallaRicerca & "*"") AND "
End If

If Not IsNull(Me.txtStartDate) Then
    strWhere = strWhere & "([Forms]![MENU]![Tabella1].[Form].[EnteredOn] >= " & Format(Me.txtStartDate, conJetDate) & ") AND "
End If


If Not IsNull(Me.txtEndDate) Then  
    strWhere = strWhere & "([Forms]![MENU]![Tabella1].[Form].[EnteredOn] < " & Format(Me.txtEndDate + 1, conJetDate) & ") AND "
End If

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then    
    MsgBox "Inserisci almeno un criterio.", vbInformation, "Nessun criterio inserito"
Else                    
    strWhere = Left$(strWhere, lngLen)

    Forms!MENU!Tabella1.Form.Filter = strWhere
    Forms!MENU!Tabella1.Form.FilterOn = True
End If

End Sub

Private Sub cmdReset_Click()

Dim ctl As Control

For Each ctl In Me.Section(acDetail).Controls
    Select Case ctl.ControlType
    Case acTextBox, acComboBox
        ctl.Value = Null
    Case acCheckBox
        ctl.Value = False
    End Select
Next

Forms!MENU!Tabella1.Form.FilterOn = False

End Sub

如果您需要任何其他信息,请告诉我,如果我不够清楚,请提前抱歉。

截图

之前的表格菜单:

表单 MENU 之后:

【问题讨论】:

  • 那么为什么要打开数据表?显示其余代码。单独的查询语句不会导致工作表打开。评论allenbrowne.com/ser-62.html
  • @June7 感谢您的帮助,非常有用!现在我刚刚更新了我的问题。不幸的是我还有一个问题..

标签: forms ms-access vba


【解决方案1】:

已解决
我的错误在于引用表格fields。例如,我将[Forms]![MENU]![Tabella1].[Form].[REGIONE SOCIALE] 更改为[REGIONE SOCIALE],将[Forms]![MENU]![Tabella1].[Form].[EnteredOn] 更改为[INSERITO IL],等等。
无论如何感谢@June7 的宝贵指南!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多