gpt4 book ai didi

vba - 达到 ComboBox 最大记录数

转载 作者:搜寻专家 更新时间:2023-10-30 23:33:23 25 4
gpt4 key购买 nike

我在 MySQL 中有一个表,通过 Microsoft Access 2013 中的链接表(通过 ODBC) Access 。

此表包含超过 124,000 条记录,我需要一个表单中的 ComboBox 才能搜索 UPC 列。

这是 ComboBox 当前数据源的查询:

SELECT [ID], [UPC_Case], [Description] FROM itemlist ORDER BY [UPC_Case];

除了 ComboBox 下的表格 View 不会超过记录号 62287(但是自动填充仍然适用于表格看不到的记录)之外,这非常有效,有没有办法让它能够查看所有记录?

最佳答案

Access 组合框的最大记录数为 65535。

为了避免这种情况,我找到了 an article这为我编写了一个函数所需的基础工作,该函数在键入一定数量的字符后动态设置 rowSource。

这是设置行源的函数。我重构了代码,以便它可以在具有任何查询的任何表单中的任何组合框上使用。

Dim inputStub As String

Function ComboLimiter(targetCombo As ComboBox, minChars As Integer, Query As String, searchField As String)
Dim inputStr As String: inputStr = targetCombo.Text 'Set input string
Dim newStub As String: newStub = Nz(Left(inputStr, minChars), "") 'Set first n characters of targetCombo.Text

If newStub <> inputStub Then 'If first n chars are the same as previously, do nothing.
If Len(newStub) < minChars Then
'Remove the RowSource
targetCombo.RowSource = Query & " WHERE (False);"
inputStub = ""
Else
'New RowSource
targetCombo.RowSource = Query & " WHERE (" & searchField & " Like """ & newStub & "*"") ORDER BY " & searchField & ";"
inputStub = newStub
End If
End If
End Function

并且该函数可以像这样绑定(bind)到 ComboBox 更改事件:

Private Sub UPCCombo_Change()
Call ComboLimiter(Me.UPCCombo, 1, _
"SELECT ID, UPC_Case, Description FROM itemlist", "UPC_Case")
End Sub

关于vba - 达到 ComboBox 最大记录数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45967043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com