简体   繁体   English

Access 2016 表单查询问题

[英]Access 2016 Form Query Issue

The query grabs/obtains the criteria from a form.查询从表单中获取/获取条件。 The problem is I have one field that is supplied in the data table that has multiple items separated by a comma.问题是我在数据表中提供了一个字段,该字段具有多个用逗号分隔的项目。 They are called Upgrade Codes :它们被称为Upgrade Codes

Example: 18AAA, 8AAA, 2GAA, 1EAA示例: 18AAA, 8AAA, 2GAA, 1EAA

在此处输入图片说明

I am using Like [Forms]![Service Action Report]![Upgrade Codes] Or Like "*" & [Forms]![Service Action Report]![Upgrade Codes] & "*" in my query and it works all but also returns similar matches.我在查询中使用Like [Forms]![Service Action Report]![Upgrade Codes] Or Like "*" & [Forms]![Service Action Report]![Upgrade Codes] & "*"也返回类似的匹配。

For example: 8AAA Form query search would return all records with 8AAA and also 18AAA since 8AAA is part of 18AAA this is not the desired outcome, is their a way to just get all records with the Upgrade Code supplied in the Form?例如: 8AAA表查询搜索将返回所有记录8AAA18AAA因为8AAA是部分18AAA这不是想要的结果,是他们的一种方式,只是获得与升级代码中的所有记录的形式提供?

Try the following:请尝试以下操作:

Like [Forms]![Service Action Report]![Upgrade Codes] Or 
Like [Forms]![Service Action Report]![Upgrade Codes] & ", *" Or 
Like "*, " & [Forms]![Service Action Report]![Upgrade Codes] & ", *" Or 
Like "*, " & [Forms]![Service Action Report]![Upgrade Codes]

By including the * , and , * in your query it actually looks like the following for a upgrade code value like 8AAA :通过在查询中包含* ,, * ,对于像8AAA这样的升级代码值,它实际上如下8AAA

Like "8AAA" Or 
Like "8AAA, *" Or 
Like "*, 8AAA, *" Or 
Like "*, 8AAA"

The differend "or" seperated statements work like follows:不同的“或”分隔语句的工作方式如下:

  1. "8AAA" : "8AAA"
    Full match of 8AAA (there are no other values in the string) 8AAA全匹配(字符串中没有其他值)
  2. "8AAA, *" : "8AAA, *" :
    Match 8AAA only if it is the first comma seperated value in the list仅当它是列表中的第一个逗号分隔值时才匹配8AAA
  3. "*, 8AAA, *" : "*, 8AAA, *" :
    Match 8AAA only if it is a middle value surounded by 2 commas比赛8AAA只有当它是由2个逗号surounded一个中间值
  4. "*, 8AAA" : "*, 8AAA" :
    Match 8AAA only if it is the last value仅当它是最后一个值时才匹配8AAA

By including the boundaries comma or beginning/end of the string you ensure that only full codes can match.通过包含边界逗号或字符串的开头/结尾,您可以确保只有完整的代码才能匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM