Wednesday, October 1, 2014

MSAccess - How to consider some part of text in a form field as a criteria in a query.

Solution 1: 3/17

This is possible using Like command, following is the example and details:


Like ([Forms]![Check QC Project set up]![Text3] & "*")  ------- here this command when placed in the query operates as a criteria.

Query is –

SELECT AMEX_FEED_MANAGEMENT_02222015.[QC Domain Name], AMEX_FEED_MANAGEMENT_02222015.[QC Project Name]

FROM AMEX_FEED_MANAGEMENT_02222015

WHERE (((AMEX_FEED_MANAGEMENT_02222015.[QC Project Name]) Like ([Forms]![Check QC Project set up]![Text3] & "*")));

Check QC Project set up - is the form name
Text3 - is where you enter the text for criteria


Solution 2: 3/19

I can also use MID and In operators:

SELECT Projects_list.Name
FROM Projects_list
WHERE MID(Projects_list.Name, 3) in (Select Project_ids.Project_ID from Project_ids);

1 comment:

  1. SELECT Projects_list.Name
    FROM Projects_list
    WHERE MID(Projects_list.Name, 3) in (Select Project_ids.Project_ID from Project_ids);

    I dont think above code will work if the In has list of project id's even if they start with "PRJ" (Ex: Mid is returning PRJ), because Project Id's would have PRJ001, PRJ002.... but not just PRJ. Here we need to use Like instead of IN.

    ReplyDelete