MS Access ListBox 所选项目

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

如何让Access中的列表框显示列表的某个值?

假设:我想显示“Alex”

Listbox值如下:

ID           Name
1             Tom
2             Peter
3             Alex
4             Susanne

通常它适用于

Forms("Trade").Controls("Erfassung").Column(0) = 3   Listbox shows “3, Alex”

但是使用 ADODB.Connection 填充列表框不再起作用了。

Dim DBSQL As New ADODB.Connection
Dim RSSQL As New ADODB.Recordset

DBSQL.ConnectionString = CONSTRING
DBSQL.Open


SQL = "SELECT [ID], [Name] FROM [Clients] ORDER BY [Name] ASC; "
RSSQL.Open SQL, DBSQL, adOpenKeyset, adLockOptimistic
Set Forms!Trade.Erfassung_Client.Recordset = RSSQL
RSSQL.Close


Forms("Trade").Controls("Erfassung").Column(0)  -> results in runtime error 451
Forms("Trade").Controls("Erfassung").value = 3 -> Listbox shows “4, Susanne” because Susanne is the 3rd value in the sorted List

如何让列表框显示“3, Alex”? (没有弄清楚亚历克斯在哪个位置的解决方法)

sql vba ms-access listbox
© www.soinside.com 2019 - 2024. All rights reserved.