Returning records that partially match a value

前端 未结 5 548
悲哀的现实
悲哀的现实 2021-01-06 07:13

I\'m trying to get a query working that takes the values (sometimes just the first part of a string) from a form control. The problem I have is that it only returns records

5条回答
  •  既然无缘
    2021-01-06 07:56

    This is a complete re-write to allow for nulls in the name fields or the date of birth field. This query will not fail as too complex if text is entered in the numeric customerid field.

    SELECT TabCustomers.CustomerForname AS NameSearch, TabCustomers.CustomerSurname AS SurnameSearch, TabCustomers.CustomerDOB AS DOBSearch, TabCustomers.customerid AS MemberSearch
    FROM TabCustomers
    WHERE TabCustomers.customerid Like IIf([Forms]![FrmSearchCustomer].[Searchmember] Is Null,"*",[Forms]![FrmSearchCustomer]![Searchmember])
    AND Trim(TabCustomers.CustomerForname & "") Like IIf([Forms]![FrmSearchCustomer].[SearchFore] Is Null,"*",[Forms]![FrmSearchCustomer]![SearchFore] & "*")
    AND Trim(TabCustomers.CustomerSurname & "") like IIf([Forms]![FrmSearchCustomer].[Searchlast] Is Null,"*",[Forms]![FrmSearchCustomer]![SearchLast] & "*")
    AND (TabCustomers.CustomerDOB Like IIf([Forms]![FrmSearchCustomer].[SearchDate] Is Null,"*",[Forms]![FrmSearchCustomer]![SearchDate] ) Or TabCustomers.CustomerDOB Is Null)
    

提交回复
热议问题