Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL查询忽略它引用的控件_Sql_Ms Access_Ms Access 2010 - Fatal编程技术网

SQL查询忽略它引用的控件

SQL查询忽略它引用的控件,sql,ms-access,ms-access-2010,Sql,Ms Access,Ms Access 2010,我有一个访问表单,其中包含一个从以下查询获取数据的列表框: SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR AS [Retro Frei], tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status], tblISIN_Country_Table.Country FROM (tblFUNDS

我有一个访问表单,其中包含一个从以下查询获取数据的列表框:

SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR AS [Retro Frei], 
tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status], 
tblISIN_Country_Table.Country

FROM 
(tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN) 
INNER JOIN tblMorningstar_Data ON 
(tblFUNDS.Fund_Selection = tblMorningstar_Data.Fund_Selection) 
AND (tblFUNDS.ISIN = tblMorningstar_Data.ISIN)

GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, 
tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status], 
tblISIN_Country_Table.Country, tblFUNDS.Fund_Selection

HAVING (((tblFUNDS.RDR) Like Nz([Forms]![frmMain]![ddnRDR],'*')) AND
((tblMorningstar_Data.[DEU Tax Transparence]) Like Nz([Forms]![frmMain]![ddnTax],'*')) AND
((tblMorningstar_Data.[Distribution Status]) Like Nz([Forms]![frmMain]![ddnDistribution],'*')) 
AND ((tblISIN_Country_Table.Country) Like Nz([Forms]![frmMain]![ddnCountry].[Text],'*')) 
AND ((tblFUNDS.Fund_Selection)=0));
我已经设置了查询引用的各种控件,以便在单击各种下拉字段的
\u AfterUpdate
事件上运行上述相同的SQL语句。它们都会执行,我可以通过a)列表框更新和b)设置断点来判断

问题在于: 例如,当我更改country下拉字段的值时,它会按国家过滤。然后,如果我为Tax设置下拉字段,它将为Tax进行文件归档,但忽略在country下拉控件中设置的值(以及其他下拉控件中的所有值)

我的问题: 为什么会发生这种情况?我如何让它一次根据所有下拉字段的值进行筛选?

与“注释”类似,请尝试:

SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR AS [Retro Frei], tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status], tblISIN_Country_Table.Country

FROM (tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN) INNER JOIN tblMorningstar_Data ON (tblFUNDS.Fund_Selection = tblMorningstar_Data.Fund_Selection) AND (tblFUNDS.ISIN = tblMorningstar_Data.ISIN)

WHERE (((tblFUNDS.RDR) Like Nz([Forms]![frmMain]![ddnRDR],'*')) AND ((tblMorningstar_Data.[DEU Tax Transparence]) Like Nz([Forms]![frmMain]![ddnTax],'*')) AND ((tblMorningstar_Data.[Distribution Status]) Like Nz([Forms]![frmMain]![ddnDistribution],'*')) AND ((tblISIN_Country_Table.Country) Like Nz([Forms]![frmMain]![ddnCountry].[Text],'*')) AND ((tblFUNDS.Fund_Selection)=0))

GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status], tblISIN_Country_Table.Country, tblFUNDS.Fund_Selection;
像在评论中一样,尝试:

SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR AS [Retro Frei], tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status], tblISIN_Country_Table.Country

FROM (tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN) INNER JOIN tblMorningstar_Data ON (tblFUNDS.Fund_Selection = tblMorningstar_Data.Fund_Selection) AND (tblFUNDS.ISIN = tblMorningstar_Data.ISIN)

WHERE (((tblFUNDS.RDR) Like Nz([Forms]![frmMain]![ddnRDR],'*')) AND ((tblMorningstar_Data.[DEU Tax Transparence]) Like Nz([Forms]![frmMain]![ddnTax],'*')) AND ((tblMorningstar_Data.[Distribution Status]) Like Nz([Forms]![frmMain]![ddnDistribution],'*')) AND ((tblISIN_Country_Table.Country) Like Nz([Forms]![frmMain]![ddnCountry].[Text],'*')) AND ((tblFUNDS.Fund_Selection)=0))

GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status], tblISIN_Country_Table.Country, tblFUNDS.Fund_Selection;
像在评论中一样,尝试:

SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR AS [Retro Frei], tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status], tblISIN_Country_Table.Country

FROM (tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN) INNER JOIN tblMorningstar_Data ON (tblFUNDS.Fund_Selection = tblMorningstar_Data.Fund_Selection) AND (tblFUNDS.ISIN = tblMorningstar_Data.ISIN)

WHERE (((tblFUNDS.RDR) Like Nz([Forms]![frmMain]![ddnRDR],'*')) AND ((tblMorningstar_Data.[DEU Tax Transparence]) Like Nz([Forms]![frmMain]![ddnTax],'*')) AND ((tblMorningstar_Data.[Distribution Status]) Like Nz([Forms]![frmMain]![ddnDistribution],'*')) AND ((tblISIN_Country_Table.Country) Like Nz([Forms]![frmMain]![ddnCountry].[Text],'*')) AND ((tblFUNDS.Fund_Selection)=0))

GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status], tblISIN_Country_Table.Country, tblFUNDS.Fund_Selection;
像在评论中一样,尝试:

SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR AS [Retro Frei], tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status], tblISIN_Country_Table.Country

FROM (tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN) INNER JOIN tblMorningstar_Data ON (tblFUNDS.Fund_Selection = tblMorningstar_Data.Fund_Selection) AND (tblFUNDS.ISIN = tblMorningstar_Data.ISIN)

WHERE (((tblFUNDS.RDR) Like Nz([Forms]![frmMain]![ddnRDR],'*')) AND ((tblMorningstar_Data.[DEU Tax Transparence]) Like Nz([Forms]![frmMain]![ddnTax],'*')) AND ((tblMorningstar_Data.[Distribution Status]) Like Nz([Forms]![frmMain]![ddnDistribution],'*')) AND ((tblISIN_Country_Table.Country) Like Nz([Forms]![frmMain]![ddnCountry].[Text],'*')) AND ((tblFUNDS.Fund_Selection)=0))

GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR, tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status], tblISIN_Country_Table.Country, tblFUNDS.Fund_Selection;

很抱歉,很明显,但是在您更新国家/地区组合框后,其他文本框的值是否仍然存在?尝试将它们传递到消息框中,或将它们存储在变量中,您可以观察这些变量,以查看到底传递给查询的参数是什么?尝试将它们传递到消息框中,或将它们存储在变量中,您可以观察这些变量,以查看到底传递给查询的参数是什么?尝试将它们传递到消息框中,或将它们存储在变量中,您可以观察这些变量,以查看到底传递给查询的参数是什么?尝试将它们传递到消息框中,或将它们存储在变量中,您可以观察这些变量,以查看到底传递给查询的参数是什么

为了完整起见,我的答案是,这样以后就更容易为其他人找到:


问题是ddnCountry表单的绑定列引用了错误的列。它与我使用ListBox查询的列不匹配

为了完整起见,我会给出我的答案,以便将来更容易为其他人找到:


问题是ddnCountry表单的绑定列引用了错误的列。它与我使用ListBox查询的列不匹配

为了完整起见,我会给出我的答案,以便将来更容易为其他人找到:


问题是ddnCountry表单的绑定列引用了错误的列。它与我使用ListBox查询的列不匹配

为了完整起见,我会给出我的答案,以便将来更容易为其他人找到:


问题是ddnCountry表单的绑定列引用了错误的列。它与我使用ListBox查询的列不匹配

很高兴听到你解决了问题。为了详细说明我的注释,我将把更改列表框的controlsource的代码放在这里。也许有一天其他人会发现它很有用。欢迎提出任何意见

Public Function Rapport_query()
Dim sqlTax As String
Dim sqlRDR As String
Dim sql As String
Dim selectQuery As String
Dim whereStatement As String
Dim i As Integer
Dim i1 As Integer
Dim i2 As Integer

'set counter (because if the filter is not the first there should be an "AND" operator before the filter.
i = 0

'check if the combobox is empty, if it's not use the input as input for you where statement
    If Not (IsNull(Forms!frmMain!ddnRDR)) Then
        i1 = i + 1
        sqlRDR = " tblFUNDS.RDR LIKE " & Chr(34) & Forms!frmMain!ddnRDR & Chr(34)
        i = i + 1
    End If

    If Not (IsNull(Forms!frmMain!ddnTax)) Then
        i2 = i + 1
        If i2 > i1 And i > 0 Then
            sqlTax = " AND tblMorningstar_Data.[DEU Tax Transparence] LIKE " & Chr(34) & Forms!frmMain!ddnTax & Chr(34)
        Else
            sqlTax = "tblMorningstar_Data.[DEU Tax Transparence] LIKE " & Chr(34) & Forms!frmMain!ddnTax & Chr(34)
        End If
        i = i + 1
    End If

'if the lenght is 0, there are no filters. Else fill the where statement string
    If Len(sqlRDR & sqlTax) = 0 Then
        whereStatement = ""
    Else
        whereStatement = "WHERE " & sqlRDR & sqlTax
    End If

'set the select query
    selectQuery = "SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR AS [Retro Frei]," & _
"tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status]," & _
"tblISIN_Country_Table.Country " & _
"FROM (tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN) " & _
"INNER JOIN tblMorningstar_Data ON (tblFUNDS.Fund_Selection = tblMorningstar_Data.Fund_Selection) " & _
"AND (tblFUNDS.ISIN = tblMorningstar_Data.ISIN) " & _
"GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR," & _
"tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status]," & _
"tblISIN_Country_Table.Country , tblFUNDS.Fund_Selection"
'combine the select query with the variable where statement
    sql = selectQuery & whereStatement

'set the listbox controlsource
    Forms!frmMain.ListBox.ControlSource = sql
End Function

很高兴听到你解决了你的问题。为了详细说明我的注释,我将把更改列表框的controlsource的代码放在这里。也许有一天其他人会发现它很有用。欢迎提出任何意见

Public Function Rapport_query()
Dim sqlTax As String
Dim sqlRDR As String
Dim sql As String
Dim selectQuery As String
Dim whereStatement As String
Dim i As Integer
Dim i1 As Integer
Dim i2 As Integer

'set counter (because if the filter is not the first there should be an "AND" operator before the filter.
i = 0

'check if the combobox is empty, if it's not use the input as input for you where statement
    If Not (IsNull(Forms!frmMain!ddnRDR)) Then
        i1 = i + 1
        sqlRDR = " tblFUNDS.RDR LIKE " & Chr(34) & Forms!frmMain!ddnRDR & Chr(34)
        i = i + 1
    End If

    If Not (IsNull(Forms!frmMain!ddnTax)) Then
        i2 = i + 1
        If i2 > i1 And i > 0 Then
            sqlTax = " AND tblMorningstar_Data.[DEU Tax Transparence] LIKE " & Chr(34) & Forms!frmMain!ddnTax & Chr(34)
        Else
            sqlTax = "tblMorningstar_Data.[DEU Tax Transparence] LIKE " & Chr(34) & Forms!frmMain!ddnTax & Chr(34)
        End If
        i = i + 1
    End If

'if the lenght is 0, there are no filters. Else fill the where statement string
    If Len(sqlRDR & sqlTax) = 0 Then
        whereStatement = ""
    Else
        whereStatement = "WHERE " & sqlRDR & sqlTax
    End If

'set the select query
    selectQuery = "SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR AS [Retro Frei]," & _
"tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status]," & _
"tblISIN_Country_Table.Country " & _
"FROM (tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN) " & _
"INNER JOIN tblMorningstar_Data ON (tblFUNDS.Fund_Selection = tblMorningstar_Data.Fund_Selection) " & _
"AND (tblFUNDS.ISIN = tblMorningstar_Data.ISIN) " & _
"GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR," & _
"tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status]," & _
"tblISIN_Country_Table.Country , tblFUNDS.Fund_Selection"
'combine the select query with the variable where statement
    sql = selectQuery & whereStatement

'set the listbox controlsource
    Forms!frmMain.ListBox.ControlSource = sql
End Function

很高兴听到你解决了你的问题。为了详细说明我的注释,我将把更改列表框的controlsource的代码放在这里。也许有一天其他人会发现它很有用。欢迎提出任何意见

Public Function Rapport_query()
Dim sqlTax As String
Dim sqlRDR As String
Dim sql As String
Dim selectQuery As String
Dim whereStatement As String
Dim i As Integer
Dim i1 As Integer
Dim i2 As Integer

'set counter (because if the filter is not the first there should be an "AND" operator before the filter.
i = 0

'check if the combobox is empty, if it's not use the input as input for you where statement
    If Not (IsNull(Forms!frmMain!ddnRDR)) Then
        i1 = i + 1
        sqlRDR = " tblFUNDS.RDR LIKE " & Chr(34) & Forms!frmMain!ddnRDR & Chr(34)
        i = i + 1
    End If

    If Not (IsNull(Forms!frmMain!ddnTax)) Then
        i2 = i + 1
        If i2 > i1 And i > 0 Then
            sqlTax = " AND tblMorningstar_Data.[DEU Tax Transparence] LIKE " & Chr(34) & Forms!frmMain!ddnTax & Chr(34)
        Else
            sqlTax = "tblMorningstar_Data.[DEU Tax Transparence] LIKE " & Chr(34) & Forms!frmMain!ddnTax & Chr(34)
        End If
        i = i + 1
    End If

'if the lenght is 0, there are no filters. Else fill the where statement string
    If Len(sqlRDR & sqlTax) = 0 Then
        whereStatement = ""
    Else
        whereStatement = "WHERE " & sqlRDR & sqlTax
    End If

'set the select query
    selectQuery = "SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR AS [Retro Frei]," & _
"tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status]," & _
"tblISIN_Country_Table.Country " & _
"FROM (tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN) " & _
"INNER JOIN tblMorningstar_Data ON (tblFUNDS.Fund_Selection = tblMorningstar_Data.Fund_Selection) " & _
"AND (tblFUNDS.ISIN = tblMorningstar_Data.ISIN) " & _
"GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR," & _
"tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status]," & _
"tblISIN_Country_Table.Country , tblFUNDS.Fund_Selection"
'combine the select query with the variable where statement
    sql = selectQuery & whereStatement

'set the listbox controlsource
    Forms!frmMain.ListBox.ControlSource = sql
End Function

很高兴听到你解决了你的问题。为了详细说明我的注释,我将把更改列表框的controlsource的代码放在这里。也许有一天其他人会发现它很有用。欢迎提出任何意见

Public Function Rapport_query()
Dim sqlTax As String
Dim sqlRDR As String
Dim sql As String
Dim selectQuery As String
Dim whereStatement As String
Dim i As Integer
Dim i1 As Integer
Dim i2 As Integer

'set counter (because if the filter is not the first there should be an "AND" operator before the filter.
i = 0

'check if the combobox is empty, if it's not use the input as input for you where statement
    If Not (IsNull(Forms!frmMain!ddnRDR)) Then
        i1 = i + 1
        sqlRDR = " tblFUNDS.RDR LIKE " & Chr(34) & Forms!frmMain!ddnRDR & Chr(34)
        i = i + 1
    End If

    If Not (IsNull(Forms!frmMain!ddnTax)) Then
        i2 = i + 1
        If i2 > i1 And i > 0 Then
            sqlTax = " AND tblMorningstar_Data.[DEU Tax Transparence] LIKE " & Chr(34) & Forms!frmMain!ddnTax & Chr(34)
        Else
            sqlTax = "tblMorningstar_Data.[DEU Tax Transparence] LIKE " & Chr(34) & Forms!frmMain!ddnTax & Chr(34)
        End If
        i = i + 1
    End If

'if the lenght is 0, there are no filters. Else fill the where statement string
    If Len(sqlRDR & sqlTax) = 0 Then
        whereStatement = ""
    Else
        whereStatement = "WHERE " & sqlRDR & sqlTax
    End If

'set the select query
    selectQuery = "SELECT tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR AS [Retro Frei]," & _
"tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status]," & _
"tblISIN_Country_Table.Country " & _
"FROM (tblFUNDS INNER JOIN tblISIN_Country_Table ON tblFUNDS.ISIN = tblISIN_Country_Table.ISIN) " & _
"INNER JOIN tblMorningstar_Data ON (tblFUNDS.Fund_Selection = tblMorningstar_Data.Fund_Selection) " & _
"AND (tblFUNDS.ISIN = tblMorningstar_Data.ISIN) " & _
"GROUP BY tblFUNDS.MorningsStar_Fund_Name, tblFUNDS.ISIN, tblFUNDS.RDR," & _
"tblMorningstar_Data.[DEU Tax Transparence], tblMorningstar_Data.[Distribution Status]," & _
"tblISIN_Country_Table.Country , tblFUNDS.Fund_Selection"
'combine the select query with the variable where statement
    sql = selectQuery & whereStatement

'set the listbox controlsource
    Forms!frmMain.ListBox.ControlSource = sql
End Function


这是运行所有
\u AfterUpdate
事件的查询吗?因为我没有看到你提到的“Tax”上的过滤器?@Wouter Yes这是所有“AfterUpdate”事件运行的查询。我拿出纳税申报单来做实验。。。很抱歉。我会把它放回去更新。就我所知,SQL基本上没有错。但是你不应该使用过滤器(也许这就是问题所在)。在WHERE语句中使用它。have是用于聚合函数的,请看这里,也许还有其他方法,它涉及一些vba编码。可以将列表框的记录源设置为在VBA中创建的查询。我以前在子表单中成功地完成了这项工作。您必须创建一个模块来检查每个文本框是否为空。如果没有,则可以在变量中创建筛选器,然后可以将所有变量组合在一起。问题是ddnCountry表单的绑定列引用了错误的列。它与我使用ListBox查询的列不匹配!谢谢你的帮助!这是运行所有
\u AfterUpdate
事件的查询吗?因为我没有看到你提到的“Tax”上的过滤器?@Wouter Yes这是所有“AfterUpdate”事件运行的查询。我拿出纳税申报单来做实验。。。很抱歉。我会把它放回去更新。就我所知,SQL基本上没有错。但是你不应该使用过滤器(也许这就是问题所在)。在WHERE语句中使用它。have是用于聚合函数的,请看这里,也许还有其他方法,它涉及一些vba编码。可以将列表框的记录源设置为在VBA中创建的查询。我以前在子表单中成功地完成了这项工作。您必须创建一个模块来检查每个文本框是否为空。如果没有,则可以在变量中创建筛选器,然后可以将所有变量组合在一起