如何在microsoft access窗体中为组合框< select all>添加功能

kse8i1jr  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(361)

因此,前几天我发布了一个关于访问表单的问题,该表单需要在2个框中添加一个“全选”选项。我可以使用一个并集将选项添加到其中的两个。然而,这些选项到目前为止还没有起到任何作用。我找到了一个从组合框中获取表单参数的查询,在这里我需要添加selectall选项,只是在盯着它看了几个小时之后我又没有任何线索了。
数据库不是我写的,它大约有10年的历史了,是给我添加一些新功能的。我这样做了,店主抱怨说“全选”按钮从来没用过。经过研究,按钮有vb脚本,清除组合框输入为空值。我计划取消这些现在,因为我已经添加了选项组合框本身。
读取组合输入的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 ) );

我知道这很混乱,很难理解,这就是为什么我要寻求帮助。我如何得到它来验证两个组合框的“全选”选项?

6kkfgxo0

6kkfgxo01#

一种非常简单的方法是将组合的绑定列设置为*:

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)

相关问题