How can I make MS Access request parameters optional?

I have a query that I would like to filter differently at different times. As I did right now, by placing the parameters in the criteria field of the corresponding request fields, however, there are many cases where I do not want to filter in the given field, but only in other fields. Is there any way that any template can be passed to the criteria parameter so that I can bypass the filtering for this particular query call?

+3
source share
6 answers

If you create your request as follows:

PARAMETERS ParamA Text ( 255 );
SELECT t.id, t.topic_id
FROM SomeTable t
WHERE t.id Like IIf(IsNull([ParamA]),"*",[ParamA])

All entries will be selected if the parameter is empty.

+12
source

, * LIKE ANSI-89.

, Access/Jet *. . Jet :% ANSI-92 * ANSI-89.

ADO ANSI-92, DAO ANSI-89, .

LIKE (.. -, mdb) : , - , , , ? , , :

NOT LIKE "*[!0-9]*"

- ( ) .mdb ADO, , . .

IMO ANSI. , , .

NOT LIKE "*[!0-9]*" AND NOT LIKE "%[!0-9]%"

Jet SQL DML/DDL . ALIKE, ANSI-92 , .

NOT ALIKE "%[!0-9]%"

. ALIKE ( , ). Jet 3.51 (Access97), Jet 4.0 (Access2000 2003) ACE (Access2007), . Access MVP. , , Jet , Access, , ( !), , Jet- .

Jet ANSI . ANSI SQL.

+3

. , :

qr = "Select Tbl_Country.* From Tbl_Country WHERE id_Country = [fid_country]"

fid_Country (, , , ..), :

qr = replace(qr,"[fid_country]","""*""")

wild cards, :

qr = "Select Tbl_Country.* From Tbl_Country _
      WHERE id_Country LIKE [fid_country]"

wild card fid_Country,

qr = replace(qr,"[fid_country]","G*")

,

set rs = currentDb.openRecordset(qr)
+1

, . ?

, , vba , .

0

, , , , VBA; , , , VBA, .

" ", ; , , , , .

( )

0

, , * , . Access 2003 (, , ), like [paramName] , , , ( ). , like [paramName] or Is Null , . ( , . , , .)

Memo, .

0

Source: https://habr.com/ru/post/1697158/


All Articles