单引号在 VBAWhere Like 中有何作用

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

以下代码用于填充 Access 2016 组合框的自动填充,但我不明白第一个 strRowSource 连接中的单引号以及第三个实例中的 *' 的作用,有人可以启发我吗?

Private Sub Supplier_Change()
Dim strRowSource As String
strRowSource = "SELECT DISTINCT [Purchase ledger].Supplier FROM [Purchase ledger]"
If Len(Me!Supplier.Text) > 2 Then 'when more than 2 characters are entered the following code      will run
 DoCmd.Beep 'Just to confirm subroutine started
 strRowSource = strRowSource & " WHERE Supplier Like '"
 strRowSource = strRowSource & Me!Supplier.Text
 strRowSource = strRowSource & "*'"
 Me!Supplier.RowSource = strRowSource
 Me!Supplier.Dropdown
 End If
 End Sub

我只是在寻找解释,因为此代码可以工作,但我不明白如何工作。

vba ms-access concatenation wildcard
1个回答
0
投票

不知道你有什么不清楚的地方。

通过使用用作组合框 RowSource 的过滤条件构建 SQL 语句,代码会在您键入时进行模式匹配并过滤组合框列表。如果您不明白什么是 SQL 语句,可以在查询对象的 SQLView 中看到它们。

撇号(又名单引号)是文本分隔符 - 它或引号(又名双引号)在查询对象中具有相同的用途。

星号是通配符。有关通配符的更多信息,请参阅 MS 文档 https://support.microsoft.com/en-us/office/use-wildcards-in-queries-and-parameters-in-access-ec057a45-78b1-4d16-8c20-242cde582e0b# :~:text=%20使用%20通配符%20in%20查询%20和%20参数%20in,视图。%20In...%204%20See%20也。%20%20See%20更多

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