如何使用Access中的VB从选择查询填充组合框?

时间:2018-07-16 17:56:13

标签: vba ms-access

我是VB的新手,正在尝试从选择查询的结果填充访问组合框,该查询从另一个组合框获取值,而我正在尝试的代码是:

Private Sub addPartsButtonForm_Click()

    ssql = "SELECT * FROM EquipmentTbl WHERE [EquipmentID] = '" & Me.equipmentCombo.Column(0) & "'"
    Me!comboParts = ssql

    Me.comboParts.Requery

End Sub

当我按下按钮时,在组合框中得到以下结果:

SELECT * FROM EquipmentTbl WHERE [EquipmentID] = '34'

尽管它给了我确切的equipmentID,但期望的是除此之外。请帮助我

1 个答案:

答案 0 :(得分:1)

设置组合RowSource。另外,如果字段为数字,则无需引号。

Dim sSql As String
    sSql = "SELECT * FROM EquipmentTbl WHERE [EquipmentID] = " & Me.equipmentCombo.Column(0) 

     Me.comboParts.RowSource = ""
    Me.comboParts.RowSource = sSql