将变量与访问表中的多个字段匹配

问题描述 投票:0回答:1

我有一个访问配置表,其中包含多行可能的配置(即类型 = 位置变量 = 代理 I、代理 II、代理 III)

**Type**          **Description**
Position      Agent I
Position      Agent II
Position      Agent III

我想将另一个 SQL 中的字段与此处列出的位置相匹配。

If str = one of the positions listed in the Config table then Boolean = True
Else 
'make a change
end if 

我该如何实现这个目标?

sql database if-statement ms-access
1个回答
0
投票

也许使用 DCount() 函数返回找到的符合条件的记录数?不太清楚你要问什么。

Public Function IsFound(ByVal stringType As String, ByVal stringValue As String) As Boolean
    IsFound = DCount("*","Config","[Type]='" & stringType & "' AND [Description]='" & stringValue & "'") > 0
End Function

然后:

Dim strType As String: strType = "Position"
Dim strValue As String: strValue = "Agent I"

If IsFound(strType, strValue) Then '...

也许您可以省略类型并仅查找值,但我还没有完全理解您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.