2013-01-24 19 views
1

所以我張貼的問題前些天有關需要有一個「全選」選項被添加到2個ComoBoxes的訪問形式。我能夠使用聯合將選項添加到其中的2個選項中。但是,這些選項目前還沒有做到。我發現,從組合框的形式爲參數,這是我需要在選項添加到選擇所有,但我沒有線索再次盯着它幾個小時後查詢。如何在Microsoft Access中組合框<Select All>添加功能形成

數據庫不是我寫的,這是大約10歲,並給了我增加一些新的功能。我已經這樣做了,主人抱怨說「全選」按鈕從來沒有工作過。經過研究,這些按鈕具有VB腳本,用於清除組合框輸入爲無效值。因爲我已經將選項添加到ComboBox本身,所以我正在計劃廢除這些。

的SQL查詢讀取組合輸入如下所示:

PARAMETERS [Forms]![ReportCentre]![cboTreatmentType] Short, [Forms]![ReportCentre]!  [cboTreatmentDate] Short; 


SELECT addresses.*, 
     [firstname] & "" & [lastname] 
     AS Name, 
     [street] & "," & [suburb] & "" & [stateorprovince] & "" & [postalcode] 
     AS 
     Address 
FROM addresses 
WHERE (((addresses.treatmentid) = [forms] ! [reportcentre] ! 
               [cbotreatmenttype].[Value]) 
     AND ((addresses.treatmentdate) = [forms] ! [reportcentre] ! 
               [cbotreatmentdate].[Value]) 
     AND ((addresses.birthmonth) LIKE [forms] ! [reportcentre] ! 
              [txtbirthmonth].[Value] 
               & "*")) 
     OR (((addresses.treatmentid) IS NULL) 
      AND 
     ((addresses.treatmentdate) = [forms] ! [reportcentre] ! 
              [cbotreatmentdate].[Value]) 
      AND ((addresses.birthmonth) LIKE [forms] ! [reportcentre] ! 
               [txtbirthmonth].[Value] 
                & "*")) 
     OR (((addresses.treatmentid) = [forms] ! [reportcentre] ! 
               [cbotreatmenttype].[Value]) 
      AND ((addresses.treatmentdate) IS NULL) 
      AND ((addresses.birthmonth) LIKE [forms] ! [reportcentre] ! 
               [txtbirthmonth].[Value] 
                & "*")) 
     OR (((addresses.treatmentid) IS NULL) 
      AND ((addresses.treatmentdate) IS NULL) 
      AND ((addresses.birthmonth) LIKE [forms] ! [reportcentre] ! 
               [txtbirthmonth].[Value] 
                & "*")) 
     OR (((addresses.treatmentid) IS NULL) 
      AND 
     ((addresses.treatmentdate) = [forms] ! [reportcentre] ! 
              [cbotreatmentdate].[Value]) 
      AND ((addresses.birthmonth) IS NULL)) 
     OR (((addresses.treatmentid) = [forms] ! [reportcentre] ! 
               [cbotreatmenttype].[Value]) 
      AND ((addresses.treatmentdate) IS NULL) 
      AND ((addresses.birthmonth) IS NULL)) 
     OR (((addresses.treatmentid) = [forms] ! [reportcentre] ! 
               [cbotreatmenttype].[Value]) 
      AND 
     ((addresses.treatmentdate) = [forms] ! [reportcentre] ! 
              [cbotreatmentdate].[Value]) 
      AND ((addresses.birthmonth) IS NULL)); 

我知道這是混亂的,很難理解,這就是爲什麼即時通訊尋求幫助。我如何獲得驗證兩個ComboBoxes的「全選」選項?

回答

1

一個非常簡單的方法是將組合到綁定列*:

SELECT "*" As ID, "Select All" As AText 
FROM Table1 
UNION SELECT Table1.ID, Table1.AText 
FROM Table1; 

使用您的組合:

Select "*" As TreatmentID, "<<All Records>>" As Treatment 
FROM Treatment 
UNION 
Select Treatment.TreatmentID, Treatment.Treatment 
From Treatment; 

然後,您可以用這樣的:

SELECT Table1.ID 
FROM Table1 
WHERE Table1.ID Like [forms]![MainForm]![Combo] 

使用您的SQL:

... WHERE (((Addresses.TreatmentID) 
    Like [Forms]![ReportCentre]![cboTreatmentType]) AND ... 

如果你只有一列,你可以使用:

SELECT Table1.Atext 
FROM Table1 
WHERE AText Like 
    IIf(Forms![MainForm]!Combo="Select All","*",Forms![MainForm]!Combo) 
相關問題