2017-07-19 64 views
0

我有一個窗體有一個名爲[Supp]的組合框,該組合框從名爲[Supplier]的表列中繪製。如何使查詢條件選擇所有如果參數爲空

同時我過濾與日期範圍記錄[Text6](開始日期)和[Text7](終止日)

我試圖讓供應商可選的過濾器相關的日期通過在您離開時選擇所有供應商[Supp]空白/空白。

問題是,無論何時我離開[Supp]空白,它都會超過Date Range過濾器,並選擇所有可用記錄,而不管日期如何。我認爲這很可能是因爲我在使用「或」。

SQL Code

SELECT [Table Material Label].Serial, [Table Material Label].[Date Recieved], [Table Material Label].MaterialDescription, [Table Material Label].MaterialCode, [Table Material Label].Supplier, 

[Table Material Label].[Lot Number], [Table Material Label].Weight, [Table Material Label].Quantity, [Table Material Label].[Purchase Order Number], [Table Material Label].[Received By], [Table Material Label].[Checked in By], [Table Material Label].[Total Weight] 

FROM [Table Material Label] 

WHERE ((([Table Material Label].[Date Recieved])>=[Forms]![Report Generator]![Text6] 
    And ([Table Material Label].[Date Recieved])<=[Forms]![Report Generator]![Text7]) 
    AND (([Table Material Label].Supplier)=IIf([forms]![Report Generator]![Supp].[Value]="*",([Table Material Label].[Supplier])='*',([Table Material Label].[Supplier])=[Forms]![Report Generator]![Supp].[Value]))) 


ORDER BY [Table Material Label].[Date Recieved], [Table Material Label].MaterialDescription, [Table Material Label].MaterialCode, [Table Material Label].Supplier; 

總結 - 我試圖做出雙方日期範圍和供應商篩選的查詢。但是如果供應商標準是空白的,我希望它不會過濾供應商。如果不打破日期範圍過濾器,我無法做到這一點。

任何幫助將不勝感激。謝謝。

成品,感謝安德烈的解決方案:

SELECT [Table Material Label].Serial, [Table Material Label].[Date Recieved], [Table Material Label].MaterialDescription, [Table Material Label].MaterialCode, [Table Material Label].Supplier, 

[Table Material Label].[Lot Number], [Table Material Label].Weight, [Table Material Label].Quantity, [Table Material Label].[Purchase Order Number], [Table Material Label].[Received By], [Table Material Label].[Checked in By], [Table Material Label].[Total Weight] 

FROM [Table Material Label] 

WHERE (([Table Material Label].[Date Recieved])>=[Forms]![Report Generator]![Text6] 
    And ([Table Material Label].[Date Recieved])<=[Forms]![Report Generator]![Text7]) 
    AND ([Table Material Label].Supplier = [Forms]![Report Generator]![Supp] 
    OR [Forms]![Report Generator]![Supp] IS NULL) 

ORDER BY [Table Material Label].[Date Recieved], [Table Material Label].MaterialDescription, [Table Material Label].MaterialCode, [Table Material Label].Supplier; 

回答

0

看吧:https://stackoverflow.com/a/38899574/3820271

AND ([Table Material Label].Supplier = [Forms]![Report Generator]![Supp] 
    OR [Forms]![Report Generator]![Supp] IS NULL) 

如果供應商的標準是空白的,那麼這和零件將永遠是正確的。

+0

感謝億安德烈,工作就像一個魅力。它驚人的組織代碼可以幫助你找到錯誤。 – Reid

相關問題