尝试根据主窗体

时间:2017-05-02 20:58:03

标签: ms-access access-vba

我看过其他一些帖子,似乎没有什么可以得到的。这个该死的Access命名法总是让我失望。

我有一个主窗体,带有子窗体。我希望能够在主窗体上的字段中输入字符串,并按如下方式过滤子窗体:

[Title on Eligibility List] like ""*" & frmNewGeneralclassification_fill_in.!txtsearchstring & "*""

这不是“链接主人和孩子”的情况。它正在进行一场相似的比赛。

我试过

me!frmNewGeneralclassification_fill_in.form.filter = "[Title on Eligibility List] like '*" & me!txtSearchString & "*'"

me.frmNewGeneralclassification_fill_in.form.filter = "[Title on Eligibility List] like '*" & me!txtSearchString & "*'"

(过滤器不是Autosense选项,但如果我输入它,它会将其大写。)

我收到“需要对象”错误消息。

其中一个应该工作,但他们不是。

frmJob_Title_Lookup.Form.RecordSource = "SELECT [Job Title to New Classification].[Title on Eligibility list], [Job Title to New Classification].Employer, [Job Title to New Classification].[New Classification in EE], [Job Title to New Classification].[New General Classification] FROM [Job Title to New Classification] WHERE ((([Job Title to New Classification].[New Classification in EE]) Is Not Null) AND (([Job Title to New Classification].[New General Classification]) Is Not Null)) and ([Title on Elibibility List] like '*" & frmNewGeneralclassification_fill_in.txtSearchString & "*'"
    frmJob_Title_Lookup.Form.Requery

我收到“Object Required”错误消息。

任何指针?

1 个答案:

答案 0 :(得分:1)

我同意在Access中引用子表单确实令人困惑。在这种情况下,请尽量不要使用' me'并完全引用您需要的内容(并记住打开过滤器):

Screenshot of my form with subform

Private Sub txtSearch_AfterUpdate()
Dim strWhere As String
strWhere = ""


If Not IsNull(Me.txtSearch) Then
    strWhere = strWhere & " ([ItemCode] like '*" & Me.txtSearch & "*' OR "
    strWhere = strWhere & " [ItemDescription] like '*" & Me.txtSearch & "*') AND "
End If


'remove final AND
If strWhere <> "" Then
    strWhere = Left(strWhere, Len(strWhere) - 5)


    Forms!frmItemList.frmItemListItemsSF.Form.Filter = strWhere
    Forms!frmItemList.frmItemListItemsSF.Form.FilterOn = True
Else
    strWhere = "1=1" 'this is always true and forces the filter to clear
    Forms!frmItemList.frmItemListItemsSF.Form.Filter = strWhere
    Forms!frmItemList.frmItemListItemsSF.Form.FilterOn = True
End If

End Sub