使用任何记录集中的数据填充 MS Access 表单中的多个值组合框

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

我有一个带有字符串类型字段的表(即表字段参数中的多值组合框)。

表格中多值字段设置

Multi-values field settings in table

我需要使用此表中单独记录集的值自动填充表单(基于此表)中的新记录。

使用通常的文本字段和具有单一选择的组合框就可以了。它有效。

常用文本字段和组合框的代码

Code for usual textfields and comboboxes

如何自动填充多值组合框?我怎样才能检测到该控件是多值组合框?

vba forms ms-access datatables
1个回答
0
投票

我会使用“ColumnCount”来表示 ctrl 有多个或没有。

'Check Multi or Single
Private Sub Combo1_Click()
 If Me.Combo1.ColumnCount > 1 Then
  MsgBox "Multi"
 Else
  MsgBox "Single"
 End If
End Sub

然后使用如下 SQL 从所选值中提取值。 :)

' Get the selected value from the ComboBox
selectedValue = Me.ComboBox1.Value

' Create a SQL query to retrieve all columns for the selected item
strSQL = "SELECT * FROM YourTableOrQuery WHERE IDField = " & selectedValue
© www.soinside.com 2019 - 2024. All rights reserved.