checkbox as query criteria

  • Follow


Hi,
in an Access form i've put a combo box that has a query as data
source. On this form I'd like to add a check box that, when it is
selected, adds the "is not null" criteria on a query field.
There is a simple way to do this?
Thank you very much for help.

--

Remigio

www.sacraspina.it
www.amicitosondoro.it
www.icmonteodorisio.it
www.parrocchiacupello.it
www.cralnuovainiziativa.it
www.associazionehistonium.it
0
Reply remigio 5/1/2010 12:55:14 PM

On Sat, 1 May 2010 05:55:14 -0700 (PDT), remigio <linoreale@gmail.com>
wrote:

Create two queries. Then switch between them based on your needs. For
example in the myCheckBox_AfterUpdate event you could write:
if me.myCheckbox.value = True then
  Me.myCombobox.RowSource = "query2"
else
  Me.myCombobox.RowSource = "query1"
end if
(of course you replace myObjectNames with yours)

-Tom.
Microsoft Access MVP


>Hi,
>in an Access form i've put a combo box that has a query as data
>source. On this form I'd like to add a check box that, when it is
>selected, adds the "is not null" criteria on a query field.
>There is a simple way to do this?
>Thank you very much for help.
0
Reply Tom 5/1/2010 1:04:03 PM


On 1 Mag, 15:04, Tom van Stiphout <tom7744.no.s...@cox.net> wrote:
> On Sat, 1 May 2010 05:55:14 -0700 (PDT), remigio <linore...@gmail.com>
> wrote:
>
> Create two queries. Then switch between them based on your needs. For
> example in the myCheckBox_AfterUpdate event you could write:
> if me.myCheckbox.value =3D True then
> =A0 Me.myCombobox.RowSource =3D "query2"
> else
> =A0 Me.myCombobox.RowSource =3D "query1"
> end if
> (of course you replace myObjectNames with yours)
>
> -Tom.
> Microsoft Access MVP
>
> >Hi,
> >in an Access form i've put a combo box that has a query as data
> >source. On this form I'd like to add a check box that, when it is
> >selected, adds the "is not null" criteria on a query field.
> >There is a simple way to do this?
> >Thank you very much for help.

Thank you very much.

--

Remigio

www.sacraspina.it
www.amicitosondoro.it
www.icmonteodorisio.it
www.parrocchiacupello.it
www.cralnuovainiziativa.it
www.associazionehistonium.it
0
Reply remigio 5/1/2010 2:31:12 PM

Remigio:

You can in fact do it with a single query as the RowSource of the combo box,
e.g.

SELECT SomeField
FROM SomeTable
WHERE Form!YourCheckBox = FALSE
OR (Form!YourCheckBox = TRUE 
AND SomeOtherField IS NOT NULL)
ORDER BY SomeField;

Note the use of the Form property to reference the current form rather than
referencing it as a member of the Forms collection.

This would return all rows from the table if the check box is not checked,
and only those where SomeOtherField contains a value if the check box is
checked.  Be sure that the check box's default value is False by putting:

Me.YourCheckBox = False

in the form's Open event procedure.  Otherwise it will be Null when the form
opens, until checked by the user.  In the checkbox's AfterUpdate event
procedure requery the combo box:

Me.YourComboBox.Requery

Ken Sheridan
Stafford, England

remigio wrote:
>Hi,
>in an Access form i've put a combo box that has a query as data
>source. On this form I'd like to add a check box that, when it is
>selected, adds the "is not null" criteria on a query field.
>There is a simple way to do this?
>Thank you very much for help.
>
>--
>
>Remigio
>
>www.sacraspina.it
>www.amicitosondoro.it
>www.icmonteodorisio.it
>www.parrocchiacupello.it
>www.cralnuovainiziativa.it
>www.associazionehistonium.it

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access/201005/1

0
Reply KenSheridan 5/1/2010 4:39:59 PM

On 1 Mag, 18:39, "KenSheridan via AccessMonster.com" <u51882@uwe>
wrote:
> Remigio:
>
> You can in fact do it with a single query as the RowSource of the combo b=
ox,
> e.g.
>
> SELECT SomeField
> FROM SomeTable
> WHERE Form!YourCheckBox =3D FALSE
> OR (Form!YourCheckBox =3D TRUE
> AND SomeOtherField IS NOT NULL)
> ORDER BY SomeField;
>
> Note the use of the Form property to reference the current form rather th=
an
> referencing it as a member of the Forms collection.
>
> This would return all rows from the table if the check box is not checked=
,
> and only those where SomeOtherField contains a value if the check box is
> checked. =A0Be sure that the check box's default value is False by puttin=
g:
>
> Me.YourCheckBox =3D False
>
> in the form's Open event procedure. =A0Otherwise it will be Null when the=
 form
> opens, until checked by the user. =A0In the checkbox's AfterUpdate event
> procedure requery the combo box:
>
> Me.YourComboBox.Requery
>
> Ken Sheridan
> Stafford, England
>
>
>
> remigio wrote:
> >Hi,
> >in an Access form i've put a combo box that has a query as data
> >source. On this form I'd like to add a check box that, when it is
> >selected, adds the "is not null" criteria on a query field.
> >There is a simple way to do this?
> >Thank you very much for help.
>
> >--
>
> >Remigio
>
> >www.sacraspina.it
> >www.amicitosondoro.it
> >www.icmonteodorisio.it
> >www.parrocchiacupello.it
> >www.cralnuovainiziativa.it
> >www.associazionehistonium.it
>
> --
> Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Foru=
ms.aspx/access/201005/1

Thank you so much!
0
Reply remigio 5/1/2010 7:36:05 PM

4 Replies
484 Views

(page loaded in 1.736 seconds)


Reply: